Skip to content

Commit

Permalink
fix(parser): fixed useless context definition, since its value is nev…
Browse files Browse the repository at this point in the history
…er read
  • Loading branch information
KFlash committed May 8, 2019
1 parent dc15c89 commit 7eec823
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# meriyah

[![CircleCI](https://circleci.com/gh/meriyah/meriyah/tree/master.svg?style=svg)](https://circleci.com/gh/meriyah/meriyah/tree/master)
[![NPM version](https://img.shields.io/npm/v/meriyah.svg?style=flat-square)](https://www.npmjs.com/package/meriyah)
[[![CircleCI](https://circleci.com/gh/meriyah/meriyah/tree/master.svg?style=svg)](https://circleci.com/gh/meriyah/meriyah/tree/master)](https://circleci.com/gh/meriyah/meriyah/tree/master)
[![Code Quality: Javascript](https://img.shields.io/lgtm/grade/javascript/g/meriyah/meriyah.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/meriyah/meriyah/context:javascript)
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/meriyah/meriyah.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/meriyah/meriyah/alerts)

A 100% compliant, self-hosted javascript parser with high focus on both performance and stability.

Expand Down
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.1.0",
"version": "0.1.1",
"description": "Fast and lightweight, standard-compliant javascript parser written in ECMAScript",
"main": "dist/meriyah.umd.js",
"module": "dist/meriyah.esm.js",
Expand Down
17 changes: 2 additions & 15 deletions src/lexer/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function scanTemplate(parser: ParserState, context: Context): Token {
ret = undefined;
ch = scanBadTemplate(parser, ch);
if (ch < 0) {
ch = -ch;
tail = false;
}
break;
Expand All @@ -43,7 +42,7 @@ export function scanTemplate(parser: ParserState, context: Context): Token {
} else {
if (ch === Chars.CarriageReturn) {
if (parser.index < parser.length && parser.source.charCodeAt(parser.index) === Chars.LineFeed) {
if (ret != null) ret += fromCodePoint(ch);
if (ret !== null) ret += fromCodePoint(ch);
parser.currentCodePoint = parser.source.charCodeAt(++parser.index);
}
}
Expand All @@ -52,7 +51,7 @@ export function scanTemplate(parser: ParserState, context: Context): Token {
parser.column = -1;
parser.line++;
}
if (ret != null) ret += fromCodePoint(ch);
if (ret !== null) ret += fromCodePoint(ch);
}
if (parser.index >= parser.length) report(parser, Errors.UnterminatedTemplate);
ch = nextCodePoint(parser);
Expand Down Expand Up @@ -84,18 +83,6 @@ function scanBadTemplate(parser: ParserState, ch: number): number {
}
break;
}

case Chars.Backslash:
ch = nextCodePoint(parser);
break;

case Chars.CarriageReturn:
if (parser.index < parser.length && parser.source.charCodeAt(parser.index) === Chars.LineFeed) {
ch = parser.source.charCodeAt(parser.index);
parser.index++;
}
// falls through

case Chars.LineFeed:
case Chars.LineSeparator:
case Chars.ParagraphSeparator:
Expand Down
21 changes: 9 additions & 12 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2902,9 +2902,8 @@ export function parseFunctionDeclaration(
params: parseFormalParametersOrFormalList(parser, context | Context.InArgList, BindingType.ArgumentList),
body: parseFunctionBody(
parser,
(context =
(context | Context.TopLevel | Context.InGlobal | Context.InSwitchOrIteration) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration)),
(context | Context.TopLevel | Context.InGlobal | Context.InSwitchOrIteration) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration),
BindingOrigin.Declaration,
firstRestricted
),
Expand Down Expand Up @@ -3154,19 +3153,19 @@ export function parseArrayExpressionOrPattern(
left = parseRestOrSpreadElement(parser, context, Token.RightBracket, bindingType, /* isAsync */ 0);
destructible |= parser.destructible;
if (parser.token !== Token.Comma && parser.token !== Token.RightBracket)
report(parser, Errors.UnexpectedToken, KeywordDescTable[(parser.token, Token.Type)]);
report(parser, Errors.UnexpectedToken, KeywordDescTable[parser.token & Token.Type]);
} else {
const isLeftParen = parser.token === Token.LeftParen;
const { token } = parser;

left = parseLeftHandSideExpression(parser, context, /* assignable */ 1);

if (parser.token !== Token.Comma && parser.token !== Token.RightBracket) {
left = parseAssignmentExpression(parser, context, left);
parser.assignable = AssignmentKind.NotAssignable;
parser.destructible = DestructuringKind.NotDestructible;
} else if (isLeftParen && parser.assignable & AssignmentKind.Assignable && !bindingType) {
} else if (token === Token.LeftParen && parser.assignable & AssignmentKind.Assignable && !bindingType) {
destructible |= DestructuringKind.Assignable;
} else if (isLeftParen || parser.assignable & AssignmentKind.NotAssignable) {
} else if (token === Token.LeftParen || parser.assignable & AssignmentKind.NotAssignable) {
destructible |= DestructuringKind.NotDestructible;
}
}
Expand Down Expand Up @@ -4357,9 +4356,8 @@ export function parseArrowFunctionExpression(
} else {
body = parseFunctionBody(
parser,
(context =
(context | Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.DisallowInContext) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.DisallowInContext)),
(context | Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.DisallowInContext) ^
(Context.InGlobal | Context.TopLevel | Context.InSwitchOrIteration | Context.DisallowInContext),
BindingOrigin.Arrow,
void 0
);
Expand Down Expand Up @@ -4827,8 +4825,7 @@ export function parseClassExpression(parser: ParserState, context: Context): EST
let superClass: ESTree.Expression | null = null;

// All class code is always strict mode implicitly
context =
(context = (context | 0b0000001000000000000_0100_00000000) ^ 0b0000001000000000000_0100_00000000) | Context.Strict;
context = ((context | 0b0000001000000000000_0100_00000000) ^ 0b0000001000000000000_0100_00000000) | Context.Strict;

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

0 comments on commit 7eec823

Please sign in to comment.