Skip to content

Commit

Permalink
fix(parser): optimization tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed May 24, 2019
1 parent 49b78e3 commit 9e983a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export const enum Errors {
DeletePrivateField,
InvalidStaticClassFieldConstructor,
InvalidClassFieldConstructor,
InvalidClassFieldArgEval
InvalidClassFieldArgEval,
InvalidGeneratorFunction
}

/*@internal*/
Expand Down Expand Up @@ -306,7 +307,8 @@ export const errorMessages: {
[Errors.DeletePrivateField]: 'Private fields can not be deleted',
[Errors.InvalidClassFieldConstructor]: 'Classes may not have a field called constructor',
[Errors.InvalidStaticClassFieldConstructor]: 'Classes may not have a private element named constructor',
[Errors.InvalidClassFieldArgEval]: 'A class field initializer may not contain arguments'
[Errors.InvalidClassFieldArgEval]: 'A class field initializer may not contain arguments',
[Errors.InvalidGeneratorFunction]: 'Generators can only be declared at the top level or inside a block'
};

export class ParseError extends SyntaxError {
Expand Down
20 changes: 7 additions & 13 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2900,7 +2900,7 @@ export function parseFunctionDeclaration(
nextToken(parser, context | Context.AllowRegExp);
let isGenerator: 0 | 1 = 0;
if (parser.token === Token.Multiply) {
if (flags & FunctionState.DisallowGenerator) report(parser, Errors.Unexpected);
if (flags & FunctionState.DisallowGenerator) report(parser, Errors.InvalidGeneratorFunction);
nextToken(parser, context);
isGenerator = 1;
}
Expand All @@ -2924,18 +2924,12 @@ export function parseFunctionDeclaration(
params: parseFormalParametersOrFormalList(parser, context | Context.InArgList, BindingType.ArgumentList),
body: parseFunctionBody(
parser,
(context |
Context.TopLevel |
Context.InGlobal |
Context.InSwitchOrIteration |
Context.InClass |
Context.DisallowIn) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.InClass | Context.DisallowIn),
context & ~(0x8001000 | Context.InGlobal | Context.InSwitchOrIteration),
BindingOrigin.Declaration,
firstRestricted
),
async: isAsync === 1,
generator: isGenerator === 1,
async: !!isAsync,
generator: !!isGenerator,
id
};
}
Expand Down Expand Up @@ -2996,8 +2990,8 @@ export function parseFunctionExpression(
type: 'FunctionExpression',
params,
body,
async: isAsync === 1,
generator: isGenerator === 1,
async: !!isAsync,
generator: !!isGenerator,
id
};
}
Expand Down Expand Up @@ -4475,7 +4469,7 @@ export function parseArrowFunctionExpression(
type: 'ArrowFunctionExpression',
body,
params,
async: isAsync === 1,
async: !!isAsync,
expression
};
}
Expand Down

0 comments on commit 9e983a8

Please sign in to comment.