Skip to content

Commit

Permalink
fix(parser): fixed LGTM warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Aug 8, 2019
1 parent 5ab88db commit 7746e25
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 168 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": "1.6.2",
"version": "1.6.3",
"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
49 changes: 38 additions & 11 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,49 @@ export function validateBindingIdentifier(

if (context & Context.Strict) {

if (t === Token.StaticKeyword) {
report(parser, Errors.InvalidStrictStatic);
if ((t & Token.FutureReserved) === Token.FutureReserved) {
report(parser, Errors.UnexpectedStrictReserved);
}

if (!skipEvalArgCheck && (t & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
report(parser, Errors.StrictEvalArguments);
}
}

if ((t & Token.Reserved) === Token.Reserved) {
report(parser, Errors.KeywordNotId);
}

// The BoundNames of LexicalDeclaration and ForDeclaration must not
// contain 'let'. (CatchParameter is the only lexical binding form
// without this restriction.)
if (kind & (BindingKind.Let | BindingKind.Const) && t === Token.LetKeyword) {
report(parser, Errors.InvalidLetConstBinding);
}

if (context & (Context.InAwaitContext | Context.Module) && t === Token.AwaitKeyword) {
report(parser, Errors.AwaitOutsideAsync);
}

if (context & (Context.InYieldContext | Context.Strict) && t === Token.YieldKeyword) {
report(parser, Errors.DisallowedInContext, 'yield');
}
}

export function validateFunctionName(
parser: ParserState,
context: Context,
_kind: BindingKind,
t: Token
): void {

if (context & Context.Strict) {

if ((t & Token.FutureReserved) === Token.FutureReserved) {
report(parser, Errors.FutureReservedWordInStrictModeNotId);
report(parser, Errors.UnexpectedStrictReserved);
}

if (!skipEvalArgCheck && (t & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
if ((t & Token.IsEvalOrArguments) === Token.IsEvalOrArguments) {
report(parser, Errors.StrictEvalArguments);
}

Expand All @@ -373,13 +407,6 @@ export function validateBindingIdentifier(
report(parser, Errors.KeywordNotId);
}

// The BoundNames of LexicalDeclaration and ForDeclaration must not
// contain 'let'. (CatchParameter is the only lexical binding form
// without this restriction.)
if (kind & (BindingKind.Let | BindingKind.Const) && t === Token.LetKeyword) {
report(parser, Errors.InvalidLetConstBinding);
}

if (context & (Context.InAwaitContext | Context.Module) && t === Token.AwaitKeyword) {
report(parser, Errors.AwaitOutsideAsync);
}
Expand Down
23 changes: 3 additions & 20 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ export const enum Errors {
DeclNoName,
StrictFunctionName,
RestMissingArg,
CantAssignToInit,
InvalidGeneratorGetter,
InvalidComputedPropName,
InvalidGetSetGenerator,
InvalidAsyncGetter,
InvalidGenMethodShorthand,
InvalidLineBreak,
InvalidAsyncParamList,
IllegalArrowFunctionParams,
InvalidArrowDestructLHS,
InvalidBindingDestruct,
InvalidAsyncArrow,
Expand Down Expand Up @@ -82,7 +79,6 @@ export const enum Errors {
SloppyFunction,
WebCompatFunction,
ClassForbiddenAsStatement,
InvalidAwaitIdent,
CantAssignToInOfForLoop,
InvalidAssignmentInOfForLoop,
InvalidForAwait,
Expand All @@ -100,9 +96,7 @@ export const enum Errors {
InvalidNewTarget,
InvalidEscapedKeyword,
MissingPrivateName,
InvalidStrictStatic,
DisallowedInContext,
FutureReservedWordInStrictModeNotId,
AwaitOutsideAsync,
InvalidStrictLet,
InvalidLetConstBinding,
Expand All @@ -125,10 +119,8 @@ export const enum Errors {
UnexpectedStrictReserved,
StrictEvalArguments,
InvalidDecoratorSemicolon,
InvalidStatementStart,
StrictDelete,
InvalidPatternTail,
ForLoopCantAssignTo,
AsyncFunctionInSingleStatementContext,
InvalidTernaryYield,
InvalidArrowPostfix,
Expand Down Expand Up @@ -227,16 +219,13 @@ export const errorMessages: {
[Errors.StrictFunctionName]:
'Function name may not contain any reserved words or be eval or arguments in strict mode',
[Errors.RestMissingArg]: 'The rest operator is missing an argument',
[Errors.CantAssignToInit]: 'Cannot assign to lhs, not destructible with this initializer',
[Errors.InvalidGeneratorGetter]: 'A getter cannot be a generator',
[Errors.InvalidComputedPropName]: 'A computed property name must be followed by a colon or paren',
[Errors.InvalidObjLitKey]: 'Object literal keys that are strings or numbers must be a method or have a colon',
[Errors.InvalidAsyncGetter]: 'Found `* async x(){}` but this should be `async * x(){}`',
[Errors.InvalidGetSetGenerator]: 'Getters and setters can not be generators',
[Errors.InvalidGenMethodShorthand]: "'%0' can not be generator method",
[Errors.InvalidLineBreak]: "No line break is allowed after '=>'",
[Errors.InvalidAsyncParamList]: 'Illegal async arrow function parameter list',
[Errors.IllegalArrowFunctionParams]: 'Illegal arrow function parameter list',
[Errors.InvalidArrowDestructLHS]: 'The left-hand side of the arrow can only be destructed through assignment',
[Errors.InvalidBindingDestruct]: 'The binding declaration is not destructible',
[Errors.InvalidAsyncArrow]: 'Async arrow can not be followed by new expression',
Expand All @@ -250,7 +239,6 @@ export const errorMessages: {
[Errors.DeclarationMissingInitializer]: 'Missing initializer in %0 declaration',
[Errors.ForInOfLoopInitializer]: "'for-%0' loop head declarations can not have an initializer",
[Errors.ForInOfLoopMultiBindings]: 'Invalid left-hand side in for-%0 loop: Must have a single binding',
[Errors.ForLoopCantAssignTo]: 'Invalid left-hand side in for-loop',
[Errors.InvalidShorthandPropInit]: 'Invalid shorthand property initializer',
[Errors.DuplicateProto]: 'Property name __proto__ appears more than once in object literal',
[Errors.InvalidLetBoundName]: 'Let is disallowed as a lexically bound name',
Expand All @@ -270,7 +258,6 @@ export const errorMessages: {
[Errors.WebCompatFunction]:
'Without web compability enabled functions can not be declared at top level, inside a block, or as the body of an if statement',
[Errors.ClassForbiddenAsStatement]: "Class declaration can't appear in single-statement context",
[Errors.InvalidAwaitIdent]: "'await' may not be used as an identifier in this context",
[Errors.CantAssignToInOfForLoop]: 'Invalid left-hand side in for-%0',
[Errors.InvalidAssignmentInOfForLoop]: 'Invalid assignment in for-%0',
[Errors.InvalidForAwait]: 'for await (... of ...) is only valid in async functions and async generators',
Expand All @@ -286,14 +273,11 @@ export const errorMessages: {
[Errors.NewlineAfterThrow]: 'Illegal newline after throw',
[Errors.StrictWith]: 'Strict mode code may not include a with statement',
[Errors.IllegalReturn]: 'Illegal return statement',
[Errors.InvalidForLHSBinding]: 'The for-header left hand side binding declaration is not destructible',
[Errors.InvalidForLHSBinding]: 'The left hand side of the for-header binding declaration is not destructible',
[Errors.InvalidNewTarget]: 'new.target only allowed within functions',
[Errors.InvalidEscapedKeyword]: 'Kasdfafdsadfsy, without embedded escapes',
[Errors.InvalidEscapedKeyword]: "'Unexpected token: 'escaped keyword'",
[Errors.MissingPrivateName]: "'#' not followed by identifier",
[Errors.InvalidStrictStatic]: '`Static` is a reserved word in strict mode',
[Errors.FutureReservedWordInStrictModeNotId]:
'The use of a future reserved word for an identifier is invalid. The identifier name is reserved in strict mode',
[Errors.KeywordNotId]: 'The use of a keyword for an identifier is invalid',
[Errors.KeywordNotId]: 'Invalid keyword',
[Errors.InvalidLetClassName]: "Can not use 'let' as a class name",
[Errors.InvalidLetConstBinding]: "'A lexical declaration can't define a 'let' binding",
[Errors.InvalidStrictLet]: 'Can not use `let` as variable name in strict mode',
Expand All @@ -316,7 +300,6 @@ export const errorMessages: {
[Errors.UnexpectedStrictReserved]: 'Unexpected strict mode reserved word',
[Errors.StrictEvalArguments]: 'Unexpected eval or arguments in strict mode',
[Errors.InvalidDecoratorSemicolon]: 'Decorators must not be followed by a semicolon',
[Errors.InvalidStatementStart]: 'A statement can not start with object destructuring assignment',
[Errors.StrictDelete]: 'Calling delete on expression not allowed in strict mode',
[Errors.InvalidPatternTail]: 'Pattern can not have a tail',
[Errors.InvalidTernaryYield]: 'Can not have a `yield` expression on the left side of a ternary',
Expand Down
2 changes: 1 addition & 1 deletion src/meriyah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ export function parse(source: string, options?: Options): ESTree.Program {
export { Options, ESTree };

// Export current version
export const version = '1.6.2';
export const version = '1.6.3';
Loading

0 comments on commit 7746e25

Please sign in to comment.