hermes-parser
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -32,3 +32,3 @@ /** | ||
this.sourceFilename = options.sourceFilename; | ||
this.sourceType = 'script'; | ||
this.sourceType = options.sourceType; | ||
} | ||
@@ -119,5 +119,14 @@ /** | ||
}, { | ||
key: "getSourceType", | ||
value: function getSourceType() { | ||
var _this$sourceType; | ||
return (_this$sourceType = this.sourceType) !== null && _this$sourceType !== void 0 ? _this$sourceType : 'script'; | ||
} | ||
}, { | ||
key: "setModuleSourceType", | ||
value: function setModuleSourceType() { | ||
this.sourceType = 'module'; | ||
if (this.sourceType == null) { | ||
this.sourceType = 'module'; | ||
} | ||
} | ||
@@ -144,2 +153,11 @@ }, { | ||
}, { | ||
key: "mapImportSpecifier", | ||
value: function mapImportSpecifier(node) { | ||
if (node.importKind === 'value') { | ||
node.importKind = null; | ||
} | ||
return this.mapNodeDefault(node); | ||
} | ||
}, { | ||
key: "mapExportDefaultDeclaration", | ||
@@ -146,0 +164,0 @@ value: function mapExportDefaultDeclaration(node) { |
@@ -40,3 +40,3 @@ /** | ||
copyToHeap(sourceBuffer, sourceAddr); | ||
var parseResult = hermesParse(sourceAddr, sourceBuffer.length + 1, options.flow === 'detect', options.tokens); | ||
var parseResult = hermesParse(sourceAddr, sourceBuffer.length + 1, options.flow === 'detect', options.tokens, options.allowReturnOutsideFunction); | ||
@@ -43,0 +43,0 @@ try { |
@@ -106,2 +106,5 @@ /** | ||
case 'ImportSpecifier': | ||
return this.mapImportSpecifier(node); | ||
case 'ExportDefaultDeclaration': | ||
@@ -138,3 +141,3 @@ return this.mapExportDefaultDeclaration(node); | ||
program.sourceType = this.sourceType; // Adjust start loc to beginning of file | ||
program.sourceType = this.getSourceType(); // Adjust start loc to beginning of file | ||
@@ -141,0 +144,0 @@ program.loc.start = { |
@@ -98,2 +98,5 @@ /** | ||
case 'ImportSpecifier': | ||
return this.mapImportSpecifier(node); | ||
case 'ExportDefaultDeclaration': | ||
@@ -120,3 +123,3 @@ return this.mapExportDefaultDeclaration(node); | ||
node = this.mapNodeDefault(node); | ||
node.sourceType = this.sourceType; | ||
node.sourceType = this.getSourceType(); | ||
return node; | ||
@@ -123,0 +126,0 @@ } |
@@ -31,3 +31,8 @@ /** | ||
if (options.sourceType != null && options.sourceType !== 'script' && options.sourceType !== 'module') { | ||
throw new Error('sourceType option must be "script" or "module" if set'); | ||
} | ||
options.tokens = options.tokens === true; | ||
options.allowReturnOutsideFunction = options.allowReturnOutsideFunction === true; | ||
return options; | ||
@@ -34,0 +39,0 @@ } |
{ | ||
"name": "hermes-parser", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A JavaScript parser built from the Hermes engine", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -7,4 +7,6 @@ # hermes-parser | ||
- **babel**: `boolean`, defaults to `false`. If `true`, output an AST conforming to Babel's AST format. If `false`, output an AST conforming to the ESTree AST format. | ||
- **allowReturnOutsideFunction**: `boolean`, defaults to `false`. If `true`, do not error on return statements found outside functions. | ||
- **flow**: `"all"` or `"detect"`, defaults to `"detect"`. If `"detect"`, only parse syntax as Flow syntax where it is ambiguous whether it is a Flow feature or regular JavaScript when the `@flow` pragma is present in the file. Otherwise if `"all"`, always parse ambiguous syntax as Flow syntax regardless of the presence of an `@flow` pragma. For example `foo<T>(x)` in a file without an `@flow` pragma will be parsed as two comparisons if set to `"detect"`, otherwise if set to `"all"` or the `@flow` pragma is included it will be parsed as a call expression with a type argument. | ||
- **sourceFilename**: `string`, defaults to `null`. The filename corresponding to the code that is to be parsed. If non-null, the filename will be added to all source locations in the output AST. | ||
- **sourceType**: `"module"` or `"script"`. If not set source type will be automatically detected and set to `"module"` if any ES6 imports or exports are present in the code, otherwise source type will be set to `"script"`. | ||
- **tokens**: `boolean`, defaults to `false`. If `true`, add all tokens to a `tokens` property on the root node. |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1015575
2990
12