Skip to content

Commit

Permalink
fix(parser): tweaked performance
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jun 18, 2019
1 parent 6c44bb7 commit 4b7a9b5
Show file tree
Hide file tree
Showing 37 changed files with 3,669 additions and 528 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ A 100% compliant, self-hosted javascript parser with high focus on both performa
* Emits an ESTree-compatible abstract syntax tree.
* No backtracking
* Reduced memory usage
* Very well tested (~75 000 unit tests with full code coverage))
* Lightweight - ~74 KB minified
* Very well tested (~81 000 unit tests with full code coverage))
* Lightweight - ~76 KB minified

## ESNext features

Expand Down
61 changes: 34 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meriyah",
"version": "0.3.1",
"version": "0.4.0",
"description": "A 100% compliant, self-hosted javascript parser with high focus on both performance and stability",
"main": "dist/meriyah.umd.js",
"module": "dist/meriyah.esm.js",
Expand Down Expand Up @@ -61,27 +61,27 @@
},
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.0.7",
"@types/node": "^12.0.8",
"coveralls": "^3.0.4",
"cross-env": "^5.2.0",
"husky": "^2.4.0",
"husky": "^2.4.1",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"path": "^0.12.7",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"rollup": "^1.14.4",
"rollup": "^1.15.6",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.0.0",
"rollup-plugin-typescript2": "^0.21.1",
"rollup-plugin-typescript2": "^0.21.2",
"source-map-support": "^0.5.12",
"test262-parser-tests": "0.0.5",
"ts-node": "^8.2.0",
"ts-node": "^8.3.0",
"tsconfig-paths": "^3.8.0",
"tslint": "^5.17.0",
"tslint-microsoft-contrib": "^6.2.0",
"typescript": "^3.5.1",
"unexpected": "^11.6.0",
"typescript": "^3.5.2",
"unexpected": "^11.6.1",
"unicode-12.0.0": "^0.8.0"
},
"husky": {
Expand Down
18 changes: 7 additions & 11 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ export const enum PropertyKind {

export const enum BindingType {
None = 0,
ArgumentList = 1 << 0,
ArgList = 1 << 0,
Variable = 1 << 2,
Let = 1 << 3,
Const = 1 << 4,
Class = 1 << 5
Const = 1 << 4
}

export const enum BindingOrigin {
Expand All @@ -78,10 +77,8 @@ export const enum BindingOrigin {

export const enum AssignmentKind {
None = 0,
IsAssignable = 1 << 0,
CannotAssign = 1 << 1,
Await = 1 << 2,
Yield = 1 << 3,
Assignable = 1 << 0,
NotAssignable = 1 << 1
}

export const enum DestructuringKind {
Expand All @@ -105,7 +102,7 @@ export const enum Flags {
HasConstructor = 1 << 5,
Octals = 1 << 6,
SimpleParameterList = 1 << 7,
Yield = 1 << 8,
Yield = 1 << 8,
}

export const enum FunctionStatement {
Expand Down Expand Up @@ -334,14 +331,14 @@ export function isPropertyWithPrivateFieldKey(expr: any): boolean {
*/
export function isValidLabel(parser: ParserState, labels: any, name: string, isIterationStatement: 0 | 1): 0 | 1 {

do {
while (labels) {
if (labels['€' + name]) {
if (isIterationStatement) report(parser, Errors.InvalidNestedStatement);
return 1;
}
if (isIterationStatement && labels.loop) isIterationStatement = 0;
labels = labels['€'];
} while (labels);
}

return 0;
}
Expand All @@ -356,7 +353,6 @@ export function isValidLabel(parser: ParserState, labels: any, name: string, isI
*/
export function validateAndDeclareLabel(parser: ParserState, labels: any, name: string): void {
let set = labels;

do {
if (set['€' + name]) report(parser, Errors.LabelRedeclaration, name);
set = set['€'];
Expand Down
14 changes: 12 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ export const enum Errors {
ImportNotOneArg,
InvalidImportNew,
InvalidSpreadInImport,
UncompleteArrow
UncompleteArrow,
DuplicateBinding,
DuplicateExportBinding,
UndeclaredExportedBinding,
UnexpectedPrivateField,
DuplicateLetConstBinding
}

/*@internal*/
Expand Down Expand Up @@ -328,7 +333,12 @@ export const errorMessages: {
[Errors.ImportNotOneArg]: 'import() requires exactly one argument',
[Errors.InvalidImportNew]: 'Cannot use new with import(...)',
[Errors.InvalidSpreadInImport]: '... is not allowed in import()',
[Errors.UncompleteArrow]: "Expected '=>'"
[Errors.UncompleteArrow]: "Expected '=>'",
[Errors.DuplicateBinding]: "Duplicate binding '%0'",
[Errors.DuplicateExportBinding]: "Cannot export a duplicate name '%0'",
[Errors.DuplicateLetConstBinding]: 'Duplicate %0 for-binding',
[Errors.UndeclaredExportedBinding]: "Exported binding '%0' needs to refer to a top-level declared variable",
[Errors.UnexpectedPrivateField]: 'Unexpected private field'
};

export class ParseError extends SyntaxError {
Expand Down

0 comments on commit 4b7a9b5

Please sign in to comment.