Skip to content

Commit

Permalink
Finished to fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelMayer committed Mar 15, 2019
1 parent d25c004 commit 200c15c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 50 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"scripts": {
"check-version": "node test/check-version.js",
"tslint": "tslint src/*.ts",
"fixlint": "tslint --fix src/*.ts",
"code-style": "tsfmt --verify src/*.ts && tsfmt --verify test/*.js",
"format-code": "tsfmt -r src/*.ts && tsfmt -r test/*.js",
"complexity": "node test/check-complexity.js",
Expand Down
12 changes: 6 additions & 6 deletions src/jsx-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class JSXParser extends Parser {
const wsStart = this.scanner.index;
this.collectComments();
const tokenStart = this.scanner.index;
const wsBefore = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const wsBefore = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);

return {wsBefore, node: {
index: this.scanner.index,
Expand Down Expand Up @@ -282,7 +282,7 @@ export class JSXParser extends Parser {
const wsStart = this.scanner.index;
this.collectComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);

this.startMarker.index = this.scanner.index;
this.startMarker.line = this.scanner.lineNumber;
Expand Down Expand Up @@ -350,7 +350,7 @@ export class JSXParser extends Parser {
const wsStart = this.scanner.index;
this.scanner.scanComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const next = this.lexJSX(ws);
this.scanner.restoreState(state);

Expand Down Expand Up @@ -509,17 +509,17 @@ export class JSXParser extends Parser {
const wsNode = this.createJSXNode();

const wsBefore = wsNode.wsBefore + this.expectJSX('<');
let wsBeforeEnd = '';
if (this.matchJSX('/')) {
this.expectJSX('/');
const elementName = this.parseJSXElementName();
const wsBeforeEnd = this.expectJSX('>');
wsBeforeEnd = this.expectJSX('>');
return this.finalize(wsNode.node, new JSXNode.JSXClosingElement(elementName, wsBeforeEnd));
}

const name = this.parseJSXElementName();
const attributes = this.parseJSXAttributes();
const selfClosing = this.matchJSX('/');
let wsBeforeEnd = '';
if (selfClosing) {
wsBeforeEnd = this.expectJSX('/');
}
Expand All @@ -533,7 +533,7 @@ export class JSXParser extends Parser {
const wsStart = this.scanner.index;
this.collectComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
this.lastMarker.index = this.scanner.index;
this.lastMarker.line = this.scanner.lineNumber;
this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
Expand Down
77 changes: 39 additions & 38 deletions src/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export let unparseChildren = (parent: any = undefined,
join: string | string[] = '', defaultJoin = '') => (children: UnparsableOrNull[]) => {
if (children) {
const renderedChildren = children.map((child) => child ? child.unparse(parent) : '');
if (typeof join == 'string') {
if (typeof join === 'string') {
return renderedChildren.join(join);
}
let result = '';
Expand Down Expand Up @@ -118,10 +118,10 @@ const arrowFunctionUnparser = function(this: ArrowFunctionExpression | AsyncArro
return this.wsBefore +
(this.async ? this.wsBeforeAsync + 'async' : '') +
this.wsBeforeOpening +
(this.params.length == 1 && this.noparens ? '' : '(') +
(this.params.length === 1 && this.noparens ? '' : '(') +
unparseChildren(this, this.separators, ', ')(this.params) +
this.wsBeforeClosing +
(this.params.length == 1 && this.noparens ? '' : ')') +
(this.params.length === 1 && this.noparens ? '' : ')') +
this.wsBeforeArrow +
this.arrow +
unparseChild(this)(this.body) +
Expand Down Expand Up @@ -252,7 +252,7 @@ AsyncFunctionExpression | FunctionExpression;
// Context-sensitive unparsing definition.
// If a method, the async and generator (*) are already managed, and the word "function" does not appear.
const functionDeclarationUnparser = function(this: AnyFunctionExpression, parent) {
const isFunctionMethod = parent && (parent.type == Syntax.Property && (parent.method || parent.kind == 'get' || parent.kind == 'set') || parent.type == Syntax.MethodDefinition);
const isFunctionMethod = parent && (parent.type === Syntax.Property && (parent.method || parent.kind === 'get' || parent.kind === 'set') || parent.type === Syntax.MethodDefinition);
return this.wsBefore +
(isFunctionMethod ? '' :
this.async ? this.wsBeforeAsync + 'async' : '') +
Expand Down Expand Up @@ -835,7 +835,7 @@ export class ExportSpecifier {
const exportedStr = unparseChild(this)(this.exported);
return this.wsBefore +
localStr +
(this.noAs && localStr == exportedStr ?
(this.noAs && localStr === exportedStr ?
''
: this.wsBeforeAs + 'as' + unparseChild(this)(this.exported)) +
this.wsAfter;
Expand Down Expand Up @@ -1055,7 +1055,7 @@ export class Identifier {
wsBefore: string;
readonly wsAfter: string = '';
unparse(parent?: Unparsable): string {
return this.wsBefore + (this.name == this.original ? this.nameRaw : this.name) + this.wsAfter;
return this.wsBefore + (this.name === this.original ? this.nameRaw : this.name) + this.wsAfter;
}
constructor(wsBefore: string, name: string, nameRaw: string) {
this.type = Syntax.Identifier;
Expand Down Expand Up @@ -1131,13 +1131,13 @@ export class ImportDeclaration {
wsAfter: string = '';
unparse(parent?: Unparsable): string {
let result = this.wsBefore + 'import';
if (this.specifiers.length == 0 && !this.hasBrackets) {
if (this.specifiers.length === 0 && !this.hasBrackets) {
return result + unparseChild(this)(this.source) + this.semicolon + this.wsAfter;
}
let insideImportSpecifiers = false;
for (let i = 0; i < this.specifiers.length; i++) {
const specifier = this.specifiers[i];
if (specifier.type == Syntax.ImportSpecifier) {
if (specifier.type === Syntax.ImportSpecifier) {
if (!insideImportSpecifiers) {
result += this.wsBeforeOpening + '{';
insideImportSpecifiers = true;
Expand Down Expand Up @@ -1248,51 +1248,52 @@ export class LabeledStatement {
this.wsBeforeColon = wsBeforeColon;
}
}
function unescapeCharSequence(string: string): string {
return string.replace(/[\\\b\f\n\r\t\v]/g, function(m) {
switch (m) {
case '\\': return '\\\\';
case '\b': return '\\b';
case '\f': return '\\f';
case '\n': return '\\n';
case '\r': return '\\r';
case '\t': return '\\t';
case '\v': return '\\v';
default: return m;
}
});
function unescapeChar(m) {
switch (m) {
case '\\': return '\\\\';
case '\b': return '\\b';
case '\f': return '\\f';
case '\n': return '\\n';
case '\r': return '\\r';
case '\t': return '\\t';
case '\v': return '\\v';
default: return m;
}
}
function unescapeCharSequence(str: string): string {
return str.replace(/[\\\b\f\n\r\t\v]/g, unescapeChar);
}

function uneval(x: any): string {
if (typeof x == 'string') {
if (typeof x === 'string') {
return toExpString(x);
}
if (typeof x == 'number' || typeof x == 'boolean') {
if (typeof x === 'number' || typeof x === 'boolean') {
return '' + x;
}
if (typeof x == 'object' && x == null) {
if (typeof x === 'object' && x === null) {
return 'null';
}
if (typeof x == 'object' && typeof x.length == 'number') { // Arrays
if (typeof x === 'object' && typeof x.length === 'number') { // Arrays
const result: string[] = [];
x = x as any[];
for (let i = 0; i < x.length; i++) {
result.push(uneval(x[i]));
}
return '[' + result.join(',') + ']';
}
if (typeof x == 'object') {
if (typeof x === 'object') {
const result: string[] = [];
for (const k in x) {
for (const k of Object.keys(x)) {
result.push(k + ':' + uneval(x[k]));
}
return '{' + result.join(', ') + '}';
}
return '' + x;
}
function toExpString(string, raw?) {
const charDelim = raw && raw.length >= 1 && (raw[0] == '"' || raw[0] == '`' || raw[0] == '\'') ? raw[0] : '"';
return charDelim + unescapeCharSequence(string).replace(charDelim, '\\' + charDelim) + charDelim;
function toExpString(str, raw?) {
const charDelim = raw && raw.length >= 1 && (raw[0] === '"' || raw[0] === '`' || raw[0] === '\'') ? raw[0] : '"';
return charDelim + unescapeCharSequence(str).replace(charDelim, '\\' + charDelim) + charDelim;
}

export class Literal {
Expand All @@ -1305,9 +1306,9 @@ export class Literal {
unparse(parent?: Unparsable): string {
return this.wsBefore +
(this.original === this.value ? this.raw :
typeof this.value == 'string' ?
typeof this.value === 'string' ?
toExpString(this.value, this.raw) :
typeof this.value == 'object' ?
typeof this.value === 'object' ?
this.value === null ?
'null' :
uneval(this.value) :
Expand Down Expand Up @@ -1364,7 +1365,7 @@ export class MethodDefinition {
(this.value && isFunctionExpression(this.value) ?
(this.value.async ? this.value.wsBeforeAsync + 'async' : '') +
(this.value.generator ? this.value.wsBeforeStar + '*' : '') : '') +
(this.kind == 'set' || this.kind == 'get' ? this.wsBeforeGetSet + this.kind : '') +
(this.kind === 'set' || this.kind === 'get' ? this.wsBeforeGetSet + this.kind : '') +
(this.computed ? this.wsBeforeOpening + '[' : '') +
keyStr +
(this.computed ? this.wsBeforeClosing + ']' : '') +
Expand Down Expand Up @@ -1504,9 +1505,9 @@ export class Property {
(this.value.async ? this.value.wsBeforeAsync + 'async' : '') +
(this.value.generator ? this.value.wsBeforeStar + '*' : '') : ''
: '') +
(this.kind == 'get' || this.kind == 'set' ? this.wsBeforeGetSet + this.kind : '') +
(this.kind === 'get' || this.kind === 'set' ? this.wsBeforeGetSet + this.kind : '') +
(!this.shorthand || (this.value && !ap) ? (this.computed ? this.wsBeforeOpening + '[' : '') + unparseChild(this)(this.key) + (this.computed ? this.wsBeforeClosing + ']' : '') : '') +
(this.method || this.shorthand || this.kind == 'get' || this.kind == 'set' ? '' : this.wsBeforeColon + ':') +
(this.method || this.shorthand || this.kind === 'get' || this.kind === 'set' ? '' : this.wsBeforeColon + ':') +
(this.shorthand && !ap ? '' : unparseChild(this)(this.value)) + this.wsAfter;
}
constructor(kind: 'init' | 'get' | 'set', key: PropertyKey, wsBeforeGetSet: string, wsBeforeOpening: string, wsBeforeClosing: string, wsBeforeColon: string, computed: boolean, value: PropertyValue | null, method: boolean, shorthand: boolean) {
Expand Down Expand Up @@ -1534,8 +1535,8 @@ export class RegexLiteral {
wsAfter: string = '';
unparse(parent?: Unparsable): string {
return this.wsBefore +
(this.original.pattern == this.regex.pattern &&
this.original.flags == this.regex.flags ? this.raw :
(this.original.pattern === this.regex.pattern &&
this.original.flags === this.regex.flags ? this.raw :
'/' +
this.regex.pattern +
'/' +
Expand Down Expand Up @@ -1772,7 +1773,7 @@ export class TemplateElement {
wsAfter: string = '';
unparse(parent?: Unparsable): string {
return this.wsBefore +
(this.value.cooked == this.originalCooked ? this.value.raw :
(this.value.cooked === this.originalCooked ? this.value.raw :
this.value.cooked.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${')) +
this.wsAfter;
}
Expand Down
10 changes: 5 additions & 5 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class Parser {
const wsStart = this.scanner.index;
this.collectComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);

if (this.scanner.index !== this.startMarker.index) {
this.startMarker.index = this.scanner.index;
Expand Down Expand Up @@ -664,7 +664,7 @@ export class Parser {
if (this.matchAsyncFunction()) {
expr = this.parseFunctionExpression();
} else {
const token = this.nextToken();
token = this.nextToken();
expr = this.finalize(node, new Node.Identifier(token.wsBefore, token.value as string, this.getTokenRaw(token)));
}
break;
Expand Down Expand Up @@ -1382,7 +1382,7 @@ export class Parser {
const wsStart = this.scanner.index;
this.collectComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const next = this.scanner.lex(ws);
this.scanner.restoreState(state);
match = (next.type === Token.Punctuator) && (next.value === '(');
Expand Down Expand Up @@ -2074,7 +2074,7 @@ export class Parser {
const wsStart = this.scanner.index;
this.collectComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);

const next = this.scanner.lex(ws);
this.scanner.restoreState(state);
Expand Down Expand Up @@ -3119,7 +3119,7 @@ export class Parser {
const wsStart = this.scanner.index;
this.scanner.scanComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const next = this.scanner.lex(ws);
this.scanner.restoreState(state);

Expand Down
2 changes: 1 addition & 1 deletion src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class Tokenizer {
const wsStart = this.scanner.index;
const comments: Comment[] = this.scanner.scanComments();
const tokenStart = this.scanner.index;
const ws = tokenStart == wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
const ws = tokenStart === wsStart ? '' : this.scanner.source.substring(wsStart, tokenStart);
if (this.scanner.trackComment) {
for (let i = 0; i < comments.length; ++i) {
const e: Comment = comments[i];
Expand Down

0 comments on commit 200c15c

Please sign in to comment.