Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / handlebars / print-script
1 #! /usr/bin/env node
2 /* eslint-disable no-console, no-var */
3 // Util script for debugging source code generation issues
4
5 var script = process.argv[2].replace(/\\n/g, '\n'),
6     verbose = process.argv[3] === '-v';
7
8 var Handlebars = require('./lib'),
9     SourceMap = require('source-map'),
10       SourceMapConsumer = SourceMap.SourceMapConsumer;
11
12 var template = Handlebars.precompile(script, {
13       srcName: 'input.hbs',
14       destName: 'output.js',
15
16       assumeObjects: true,
17       compat: false,
18       strict: true,
19       trackIds: true,
20       knownHelpersOnly: false
21     });
22
23 if (!verbose) {
24   console.log(template);
25 } else {
26   var consumer = new SourceMapConsumer(template.map),
27       lines = template.code.split('\n'),
28       srcLines = script.split('\n');
29
30   console.log();
31   console.log('Source:');
32   srcLines.forEach(function(source, index) {
33     console.log(index + 1, source);
34   });
35   console.log();
36   console.log('Generated:');
37   console.log(template.code);
38   lines.forEach(function(source, index) {
39     console.log(index + 1, source);
40   });
41   console.log();
42   console.log('Map:');
43   console.log(template.map);
44   console.log();
45
46   function collectSource(lines, lineName, colName, order) {
47     var ret = {},
48         ordered = [],
49         last;
50
51     function collect(current) {
52       if (last) {
53         var mapLines = lines.slice(last[lineName] - 1, current && current[lineName]);
54         if (mapLines.length) {
55           if (current) {
56             mapLines[mapLines.length - 1] = mapLines[mapLines.length - 1].slice(0, current[colName]);
57           }
58           mapLines[0] = mapLines[0].slice(last[colName]);
59         }
60         ret[last[lineName] + ':' + last[colName]] = mapLines.join('\n');
61         ordered.push({
62           startLine: last[lineName],
63           startCol: last[colName],
64           endLine: current && current[lineName]
65         });
66       }
67       last = current;
68     }
69
70     consumer.eachMapping(collect, undefined, order);
71     collect();
72
73     return ret;
74   }
75
76   srcLines = collectSource(srcLines, 'originalLine', 'originalColumn', SourceMapConsumer.ORIGINAL_ORDER);
77   lines = collectSource(lines, 'generatedLine', 'generatedColumn');
78
79   consumer.eachMapping(function(mapping) {
80     var originalSrc = srcLines[mapping.originalLine + ':' + mapping.originalColumn],
81         generatedSrc = lines[mapping.generatedLine + ':' + mapping.generatedColumn];
82
83     if (!mapping.originalLine) {
84       console.log('generated', mapping.generatedLine + ':' + mapping.generatedColumn, generatedSrc);
85     } else {
86       console.log('map',
87           mapping.source,
88           mapping.originalLine + ':' + mapping.originalColumn,
89           originalSrc,
90           '->',
91           mapping.generatedLine + ':' + mapping.generatedColumn,
92           generatedSrc);
93     }
94   });
95 }