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 Jul 2, 2019
1 parent 2c55920 commit 7d36ae3
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 117 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-node": "^9.1.0",
"glob": "^7.1.4",
"husky": "^2.3.0",
"husky": "^2.7.0",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"path": "^0.12.7",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"rollup": "^1.16.2",
"rollup": "^1.16.3",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.0.0",
"rollup-plugin-typescript2": "^0.21.2",
Expand Down
1 change: 0 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ export class ParseError extends SyntaxError {
public line: number;
public column: number;
public description: string;
/*eslint-disable*/
constructor(startindex: number, line: number, column: number, type: Errors, ...params: string[]) {
const message =
'[' + line + ':' + column + ']: ' + errorMessages[type].replace(/%(\d+)/g, (_: string, i: number) => params[i]);
Expand Down
19 changes: 6 additions & 13 deletions src/estree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface T_Node extends T_Statement, T_Expression, T_Pattern, T_ModuleDe
MethodDefinition: MethodDefinition;
VariableDeclarator: VariableDeclarator;
}
/*eslint-disable*/
interface _Expression<T extends string> extends _Node<T> {}
interface T_Expression {
Identifier: Identifier;
Expand Down Expand Up @@ -183,7 +182,7 @@ export type Expression =
| ClassExpression
| MetaProperty
| AwaitExpression;
/*eslint-disable*/

export interface EmptyStatement extends _Node<'EmptyStatement'> {}

export interface BlockStatement extends _Node<'BlockStatement'> {
Expand Down Expand Up @@ -267,7 +266,7 @@ export interface ForOfStatement extends _Statement<'ForOfStatement'> {
body: Statement;
await: boolean;
}
/*eslint-disable*/

interface _Statement<T extends string> extends _Node<T> {}
interface T_Declaration {
FunctionDeclaration: FunctionDeclaration;
Expand Down Expand Up @@ -295,13 +294,12 @@ interface T_Statement extends T_Declaration {
ForOfStatement: ForOfStatement;
Decorator: Decorator;
}
/*eslint-disable*/

export interface DebuggerStatement extends _Node<'DebuggerStatement'> {}

export type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration;

/*eslint-disable*/
interface _Declaration<T extends string> extends _Statement<T> {}
interface BaseDeclaration extends _Node<'ExpressionStatement'> {}

export interface FunctionDeclaration extends _Declaration<'FunctionDeclaration'> {
id: Identifier | null;
Expand Down Expand Up @@ -347,7 +345,6 @@ type Expression =
| Identifier
| AwaitExpression;

/*eslint-disable*/
export interface ThisExpression extends _Expression<'ThisExpression'> {}

export interface ArrayExpression extends _Expression<'ArrayExpression'> {
Expand Down Expand Up @@ -443,7 +440,6 @@ export interface CatchClause extends _Node<'CatchClause'> {
param: Pattern;
body: BlockStatement;
}
/*eslint-disable*/
interface _Pattern<T extends string> extends _Node<T> {}

interface T_Pattern {
Expand Down Expand Up @@ -521,7 +517,6 @@ export type AssignmentOperator =

export type UpdateOperator = '++' | '--';

/*eslint-disable*/
export interface Super extends _Node<'Super'> {}

export interface SpreadElement extends _Node<'SpreadElement'> {
Expand Down Expand Up @@ -643,7 +638,7 @@ interface _ModuleSpecifier<T extends string> extends _Node<T> {
}

export type ModuleSpecifier = ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier;
/*eslint-disable*/

interface _ModuleDeclaration<T extends string> extends _Node<T> {}
export interface ImportDeclaration extends _ModuleDeclaration<'ImportDeclaration'> {
specifiers: (ImportDefaultSpecifier | ImportNamespaceSpecifier | ImportSpecifier)[];
Expand All @@ -652,10 +647,8 @@ export interface ImportDeclaration extends _ModuleDeclaration<'ImportDeclaration
export interface ImportSpecifier extends _ModuleSpecifier<'ImportSpecifier'> {
imported: Identifier;
}

/*eslint-disable*/
export interface ImportDefaultSpecifier extends _ModuleSpecifier<'ImportDefaultSpecifier'> {}
/*eslint-disable*/

export interface ImportNamespaceSpecifier extends _ModuleSpecifier<'ImportNamespaceSpecifier'> {}

export interface ExportNamedDeclaration extends _ModuleDeclaration<'ExportNamedDeclaration'> {
Expand Down
4 changes: 2 additions & 2 deletions src/lexer/comments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { nextCP, CharTypes, CharFlags, LexerState, scanNewLine, consumeLineFeed } from './';
import { Chars } from '../chars';
import { ParserState, Context } from '../common';
import { ParserState } from '../common';
import { report, Errors } from '../errors';

/**
Expand All @@ -10,7 +10,7 @@ import { report, Errors } from '../errors';
*/
export function skipHashBang(parser: ParserState): void {
// HashbangComment ::
// #! SingleLineCommentChars
// #! SingleLineCommentChars_opt
if (parser.nextCP === Chars.Hash && parser.source.charCodeAt(parser.index + 1) === Chars.Exclamation) {
skipSingleLineComment(parser, LexerState.None);
}
Expand Down
27 changes: 19 additions & 8 deletions src/lexer/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ export const enum LexerState {
LastIsCR = 1 << 2
}

export const enum NumberKind {
ImplicitOctal = 1 << 0,
Binary = 1 << 1,
Octal = 1 << 2,
Hex = 1 << 3,
Decimal = 1 << 4,
DecimalWithLeadingZero = 1 << 5,
Float = 1 << 6,
DecimalNumberKind = Decimal | DecimalWithLeadingZero,
ValidBigIntKind = Binary | Decimal | Hex | Octal | DecimalWithLeadingZero
}

/**
* Advances this lexer's current index.
* @param parser The parser instance
Expand All @@ -19,25 +31,24 @@ export function nextCP(parser: ParserState): number {
return (parser.nextCP = parser.source.charCodeAt(++parser.index));
}

export function consumeMultiUnitCodePoint(parser: ParserState, hi: number): boolean {
export function consumeMultiUnitCodePoint(parser: ParserState, hi: number): 0 | 1 {
// See: https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type
if ((hi & 0xfc00) !== Chars.LeadSurrogateMin) return false;
if ((hi & 0xfc00) !== Chars.LeadSurrogateMin) return 0;
const lo = parser.source.charCodeAt(parser.index + 1);
if ((lo & 0xfc00) !== 0xdc00) return false;
hi = Chars.NonBMPMin + ((hi & 0x3ff) << 10) + (lo & 0x3ff);
if ((lo & 0xfc00) !== 0xdc00) return 0;
hi = parser.nextCP = Chars.NonBMPMin + ((hi & 0x3ff) << 10) + (lo & 0x3ff);
if (((unicodeLookup[(hi >>> 5) + 0] >>> hi) & 31 & 1) === 0) {
report(parser, Errors.IllegalCaracter, fromCodePoint(hi));
}
parser.index++;
parser.column++;
parser.nextCP = hi;
return true;
return 1;
}

/**
* Use to consume a line feed instead of `scanNewLine`.
*/
export function consumeLineFeed(parser: ParserState, lastIsCR: boolean) {
export function consumeLineFeed(parser: ParserState, lastIsCR: boolean): void {
parser.nextCP = parser.source.charCodeAt(++parser.index);
parser.flags |= Flags.NewLine;
if (!lastIsCR) {
Expand All @@ -46,7 +57,7 @@ export function consumeLineFeed(parser: ParserState, lastIsCR: boolean) {
}
}

export function scanNewLine(parser: ParserState) {
export function scanNewLine(parser: ParserState): void {
parser.flags |= Flags.NewLine;
parser.nextCP = parser.source.charCodeAt(++parser.index);
parser.column = 0;
Expand Down
1 change: 0 additions & 1 deletion src/lexer/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Chars } from '../chars';
import { nextCP, consumeMultiUnitCodePoint, fromCodePoint, toHex } from './';
import { CharTypes, CharFlags, isIdentifierPart, isIdentifierStart } from './charClassifier';
import { report, reportAt, Errors } from '../errors';
import { unicodeLookup } from '../unicode';

/**
* Scans identifier
Expand Down
5 changes: 3 additions & 2 deletions src/lexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export {
toHex,
consumeLineFeed,
scanNewLine,
LexerState
LexerState,
NumberKind
} from './common';
export { CharTypes, CharFlags, isIdentifierStart, isIdentifierPart } from './charClassifier';
export {
Expand All @@ -19,6 +20,6 @@ export {
scanUnicodeEscapeValue
} from './identifier';
export { scanString } from './string';
export { scanNumber, NumberKind } from './numeric';
export { scanNumber } from './numeric';
export { scanTemplate, scanTemplateTail } from './template';
export { scanRegularExpression } from './regexp';

0 comments on commit 7d36ae3

Please sign in to comment.