8 examples of 'parse file javascript' in JavaScript

Every line of 'parse file javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
81function parseJavaScriptFiles (fileStructure) {
82 _(fileStructure.allFiles)
83 .filter(function (file) {
84 return COMPONENT_EXTENSION_REGEX.test(file.path) || STEP_DEFINITION_EXTENSION_REGEX.test(file.path);
85 })
86 .each(javaScriptParser.parse)
87 .value();
88}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

126function evalFileScript(path) {
127 return 'var scriptFile = new File(app.path + \'/Presets/Scripts/' + path + '\');'
128 + '$.evalFile(scriptFile, 30000);';
129}
39function parseJS(code) {
40 var indirect = eval
41 code = code.trim()
42 if (code) {
43 if (code.indexOf("use strict") === 1) {
44 var script = document.createElement("script")
45 script.text = code;
46 head.appendChild(script).parentNode.removeChild(script)
47 } else {
48 indirect(code)
49 }
50 }
51}
10function parse(inputFile, moduleId) {
11 var ast = getAst(inputFile);
12 var deps = parseStatic(ast, moduleId);
13
14 if (deps === undefined) {
15 deps = parseDynamic(ast);
16 }
17 return deps;
18}
55parse(scriptText) {
56 let ast = parse(scriptText, {
57 sourceType: 'module',
58 // Note that even when this option is enabled, @babel/parser could throw for unrecoverable errors.
59 // errorRecovery: true, //没啥用,碰到let和var对同一变量进行声明时,当场报错!还会中断转换进程
60 plugins: [
61 "asyncGenerators",
62 "classProperties",
63 "decorators-legacy", //"decorators",
64 "doExpressions",
65 "dynamicImport",
66 "exportExtensions",
67 "flow",
68 "functionBind",
69 "functionSent",
70 "jsx",
71 "objectRestSpread",
72 ]
73 });
74 // resolve(ast);
75
76 //使用下面的代码,在遇到解构语法(...)时,会报错,改用babel-parser方案
77 // const scriptParsed = babylon.parse(scriptText, {
78 // sourceType: 'module',
79 // plugins: [
80 // // "estree", //这个插件会导致解析的结果发生变化,因此去除,这本来是acron的插件
81 // "jsx",
82 // "flow",
83 // "doExpressions",
84 // "objectRestSpread",
85 // "exportExtensions",
86 // "classProperties",
87 // "decorators",
88 // "asyncGenerators",
89 // "functionBind",
90 // "functionSent",
91 // "throwExpressions",
92 // "templateInvalidEscapes",
93 // ]
94 // })
95 // resolve(scriptParsed);
96
97 return ast;
98}
264parseJavascript(filename, content) {
265 const jsContent = flowRemoveTypes(content).toString();
266
267 const extractedStringsFromScript = jsExtractor.extractStringsFromJavascript(filename, jsContent);
268
269 this.processStrings(extractedStringsFromScript);
270}
75function parse(file) {
76 file = file || exports.spmrcfile;
77 if (!fs.existsSync(file)) {
78 return {};
79 }
80 var data;
81 if (_cache.hasOwnProperty(file)) {
82 data = _cache[file];
83 } else {
84 data = grunt.file.read(file);
85 _cache[file] = data;
86 }
87 var value = {};
88 var lines = data.split(/\r\n|\r|\n/);
89 var section = null;
90 var match;
91 lines.forEach(function(line) {
92 if (regex.comment.test(line)) {
93 return;
94 }
95 if (regex.param.test(line)) {
96 match = line.match(regex.param);
97 if (section) {
98 value[section][match[1]] = match[2];
99 }else {
100 value[match[1]] = match[2];
101 }
102 } else if (regex.section.test(line)) {
103 match = line.match(regex.section);
104 value[match[1]] = {};
105 section = match[1];
106 } else if (line.length === 0 && section) {
107 section = null;
108 }
109 });
110 return value;
111}
37function js(file) {
38 var opts = {
39 fromString: true,
40 sourceMapUrl: false
41 };
42
43 if (file.map) {
44 opts.inSourceMap = _.isObject(file.map) ? file.map : JSON.parse(file.map);
45 opts.outSourceMap = file.destFilename + '.map';
46 }
47
48 var result = uglifyjs.minify(file.content, opts);
49
50 return Promise.resolve({ content: result.code, map: result.map });
51}

Related snippets