Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(typescript-estree): correct warnings reported by sonarlint#100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JamesHenry merged 8 commits intotypescript-eslint:masterfromarmano2:code-smell
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletionspackages/typescript-estree/src/ast-converter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,11 +11,11 @@ import { convertTokens } from './node-utils';
import ts from 'typescript';
import { Extra } from './temp-types-based-on-js-source';

export default (
export defaultfunction astConverter(
ast: ts.SourceFile,
extra: Extra,
shouldProvideParserServices: boolean
)=>{
) {
/**
* The TypeScript compiler produced fundamental parse errors when parsing the
* source.
Expand DownExpand Up@@ -59,4 +59,4 @@ export default (
}

return { estree, astMaps };
};
}
8 changes: 4 additions & 4 deletionspackages/typescript-estree/src/convert.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -694,8 +694,8 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}

if (node.type) {
(result as any).id.typeAnnotation = convertTypeAnnotation(node.type);
fixTypeAnnotationParentLocation((result as any).id);
result.id!.typeAnnotation = convertTypeAnnotation(node.type);
fixTypeAnnotationParentLocation(result.id!);
}
break;
}
Expand DownExpand Up@@ -1249,7 +1249,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
expressions: []
});

node.templateSpans.forEach((templateSpan: any) => {
node.templateSpans.forEach(templateSpan => {
(result as any).expressions.push(convertChild(templateSpan.expression));
(result as any).quasis.push(convertChild(templateSpan.literal));
});
Expand DownExpand Up@@ -1333,7 +1333,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}

if (node.questionToken) {
(parameter as any).optional = true;
parameter.optional = true;
}

if (node.modifiers) {
Expand Down
4 changes: 1 addition & 3 deletionspackages/typescript-estree/src/parser.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -213,10 +213,8 @@ function generateAST<T extends ParserOptions = ParserOptions>(
tsNodeToESTreeNodeMap?: WeakMap<object, any>;
};
} {
const toString = String;

if (typeof code !== 'string' && !((code as any) instanceof String)) {
code =toString(code);
code =String(code);
}

resetExtra();
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,3 +188,83 @@ Object {
"type": "Program",
}
`;

exports[`parse() non string code should correctly convert code to string 1`] = `
Object {
"body": Array [
Object {
"expression": Object {
"loc": Object {
"end": Object {
"column": 5,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
5,
],
"raw": "12345",
"type": "Literal",
"value": 12345,
},
"loc": Object {
"end": Object {
"column": 5,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
5,
],
"type": "ExpressionStatement",
},
],
"comments": Array [],
"loc": Object {
"end": Object {
"column": 5,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
5,
],
"sourceType": "script",
"tokens": Array [
Object {
"loc": Object {
"end": Object {
"column": 5,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
5,
],
"type": "Numeric",
"value": "12345",
},
],
"type": "Program",
}
`;
62 changes: 58 additions & 4 deletionspackages/typescript-estree/tests/lib/parse.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@
* MIT License
*/
import * as parser from '../../src/parser';
import * as astConverter from '../../src/ast-converter';
import { ParserOptions } from '../../src/temp-types-based-on-js-source';
import { createSnapshotTestBlock } from '../../tools/test-utils';

Expand All@@ -16,8 +17,8 @@ import { createSnapshotTestBlock } from '../../tools/test-utils';
describe('parse()', () => {
describe('basic functionality', () => {
it('should parse an empty string', () => {
expect((parser as any).parse('').body).toEqual([]);
expect(parser.parse('', {} as any).body).toEqual([]);
expect(parser.parse('').body).toEqual([]);
expect(parser.parse('', {}).body).toEqual([]);
});
});

Expand All@@ -33,7 +34,7 @@ describe('parse()', () => {

describe('general', () => {
const code = 'let foo = bar;';
const config = {
const config: ParserOptions = {
comment: true,
tokens: true,
range: true,
Expand All@@ -42,7 +43,60 @@ describe('parse()', () => {

it(
'output tokens, comments, locs, and ranges when called with those options',
createSnapshotTestBlock(code, config as ParserOptions)
createSnapshotTestBlock(code, config)
);
});

describe('non string code', () => {
const code = (12345 as any) as string;
const config: ParserOptions = {
comment: true,
tokens: true,
range: true,
loc: true
};

it(
'should correctly convert code to string',
createSnapshotTestBlock(code, config)
);
});

describe('loggerFn should be propagated to ast-converter', () => {
it('output tokens, comments, locs, and ranges when called with those options', () => {
const spy = jest.spyOn(astConverter, 'default');

const loggerFn = jest.fn(() => true);

parser.parse('let foo = bar;', {
loggerFn,
comment: true,
tokens: true,
range: true,
loc: true
});

expect(spy).toHaveBeenCalledWith(
jasmine.any(Object),
{
code: 'let foo = bar;',
comment: true,
comments: [],
errorOnTypeScriptSyntacticAndSemanticIssues: false,
errorOnUnknownASTType: false,
extraFileExtensions: [],
jsx: false,
loc: true,
log: loggerFn,
projects: [],
range: true,
strict: false,
tokens: jasmine.any(Array),
tsconfigRootDir: jasmine.any(String),
useJSXTextNode: false
},
false
);
});
});
});
1 change: 1 addition & 0 deletionspackages/typescript-estree/tools/test-utils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@ export function parseCodeAndGenerateServices(
* and which performs an assertion on the snapshot for the given code and config.
* @param {string} code The source code to parse
* @param {ParserOptions} config the parser configuration
* @param {boolean} generateServices Flag determining whether to generate ast maps and program or not
* @returns {jest.ProvidesCallback} callback for Jest it() block
*/
export function createSnapshotTestBlock(
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp