Skip to content

Commit

Permalink
fix(parser): tweaked bit masks
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jun 18, 2019
1 parent 83c8db0 commit 1cb0718
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "meriyah",
"version": "0.4.0",
"version": "0.4.1",
"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
4 changes: 1 addition & 3 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export const enum Context {
InMethod = 1 << 25,
AllowNewTarget = 1 << 26,
DisallowIn = 1 << 27,
InDecoratorContext = 1 << 28,
InClass = 1 << 29,
InSwitchOrIteration = InSwitch | InIteration
InClass = 1 << 28
}

export const enum PropertyKind {
Expand Down
6 changes: 3 additions & 3 deletions src/lexer/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ export function scanIdentifierSlowCase(
? Token.Identifier
: keyword === Token.YieldKeyword || !hasEscape
? keyword
: context & Context.Strict && (keyword === Token.LetKeyword || keyword === Token.StaticKeyword)
? Token.EscapedFutureReserved
: (keyword & Token.FutureReserved) === Token.FutureReserved
? context & Context.Strict && hasEscape
? context & Context.Strict
? Token.EscapedFutureReserved
: keyword
: context & Context.Strict && (keyword === Token.LetKeyword || keyword === Token.StaticKeyword)
? Token.EscapedFutureReserved
: Token.EscapedReserved;
}
return Token.Identifier;
Expand Down
18 changes: 8 additions & 10 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ export function parseStatementListItem(
return parseFunctionDeclaration(parser, context, scope, 1, HoistedFunctionFlags.None, 0, start);
// @decorator
case Token.Decorator:
if (context & Context.Module)
return parseDecorators(parser, context | Context.InDecoratorContext) as ESTree.Decorator[];
if (context & Context.Module) return parseDecorators(parser, context) as ESTree.Decorator[];
// ClassDeclaration[?Yield, ~Default]
case Token.ClassKeyword:
return parseClassDeclaration(parser, context, scope, HoistedClassFlags.None, start);
Expand Down Expand Up @@ -1268,7 +1267,7 @@ export function parseBreakStatement(
label = parseIdentifier(parser, context | Context.AllowRegExp, tokenIndex);
if (!isValidLabel(parser, labels, tokenValue, /* requireIterationStatement */ 0))
report(parser, Errors.UnknownLabel, tokenValue);
} else if ((context & Context.InSwitchOrIteration) === 0) {
} else if ((context & (Context.InSwitch | Context.InIteration)) === 0) {
report(parser, Errors.IllegalBreak);
}

Expand Down Expand Up @@ -3826,8 +3825,8 @@ export function parseFunctionDeclaration(

const body = parseFunctionBody(
parser,
(context | 0x8001000 | Context.InGlobal | Context.InSwitchOrIteration) ^
(0x8001000 | Context.InGlobal | Context.InSwitchOrIteration),
(context | 0x8001000 | Context.InGlobal | Context.InSwitch | Context.InIteration) ^
(0x8001000 | Context.InGlobal | Context.InSwitch | Context.InIteration),
context & Context.OptionsLexical ? inheritScope(innerscope, ScopeType.Block) : innerscope,
BindingOrigin.Declaration,
firstRestricted
Expand Down Expand Up @@ -3907,7 +3906,8 @@ export function parseFunctionExpression(

const body = parseFunctionBody(
parser,
context & ~(0x8001000 | Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.InClass),
context &
~(0x8001000 | Context.InGlobal | Context.TopLevel | Context.InSwitch | Context.InIteration | Context.InClass),
Context.OptionsLexical ? inheritScope(scope, ScopeType.Block) : scope,
0,
firstRestricted
Expand Down Expand Up @@ -6163,8 +6163,7 @@ export function parseClassDeclaration(
let id: ESTree.Expression | null = null;
let superClass: ESTree.Expression | null = null;

const decorators: ESTree.Decorator[] =
context & Context.OptionsNext ? parseDecorators(parser, context | Context.InDecoratorContext) : [];
const decorators: ESTree.Decorator[] = context & Context.OptionsNext ? parseDecorators(parser, context) : [];

nextToken(parser, context);

Expand Down Expand Up @@ -6256,8 +6255,7 @@ export function parseClassExpression(
// All class code is always strict mode implicitly
context = (context & ~Context.InConstructor) | Context.Strict;

const decorators: ESTree.Decorator[] =
context & Context.OptionsNext ? parseDecorators(parser, context | Context.InDecoratorContext) : [];
const decorators: ESTree.Decorator[] = context & Context.OptionsNext ? parseDecorators(parser, context) : [];

nextToken(parser, context);

Expand Down

0 comments on commit 1cb0718

Please sign in to comment.