Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42b0fcc

Browse files
armano2bradzacher
authored andcommitted
test(typescript-estree): alignment tests for TemplateLiteral node (typescript-eslint#1421)
1 parent 6c35de6 commit 42b0fcc

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,18 @@ jsxFilesWithKnownIssues.push('invalid-no-tag-name');
125125

126126
tester.addFixturePatternConfig('javascript/basics');
127127

128-
tester.addFixturePatternConfig('comments', {
128+
tester.addFixturePatternConfig('comments');
129+
130+
tester.addFixturePatternConfig('javascript/templateStrings', {
129131
ignore: [
130132
/**
131-
* Template strings seem to also be affected by the difference in opinion between different parsers in:
132-
* https://github.com/babel/babel/issues/6681
133+
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
134+
* SyntaxError: Invalid escape sequence in template
133135
*/
134-
'no-comment-template', // Purely AST diffs
135-
'template-string-block', // Purely AST diffs
136+
'error-octal-literal',
136137
],
137138
});
138139

139-
tester.addFixturePatternConfig('javascript/templateStrings', {
140-
ignore: ['**/*'],
141-
});
142-
143140
tester.addFixturePatternConfig('javascript/arrayLiteral');
144141

145142
tester.addFixturePatternConfig('javascript/simple-literals');
@@ -463,19 +460,13 @@ tester.addFixturePatternConfig('typescript/decorators/property-decorators', {
463460

464461
tester.addFixturePatternConfig('typescript/expressions', {
465462
fileType: 'ts',
466-
ignore: [
467-
/**
468-
* there is difference in range between babel and ts-estree
469-
*/
470-
'tagged-template-expression-type-arguments',
471-
],
472463
});
473464

474465
tester.addFixturePatternConfig('typescript/errorRecovery', {
475466
fileType: 'ts',
476467
ignore: [
477468
/**
478-
* [TS-ESTREE ERRORED, BUT BABEL DID NOT]
469+
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
479470
* TODO: enable error code TS1019: An index signature parameter cannot have a question mark.
480471
*/
481472
'interface-with-optional-index-signature',

packages/typescript-estree/tests/ast-alignment/utils.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
130130
/**
131131
* We want this node to be different
132132
* @see https://github.com/JamesHenry/typescript-estree/issues/109
133+
* @see https://github.com/prettier/prettier/pull/5728
133134
*/
134135
TSTypeParameter(node: any) {
135136
if (node.name) {
@@ -178,7 +179,9 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
178179
node.type = 'TSClassImplements';
179180
}
180181
},
181-
// https://github.com/prettier/prettier/issues/5817
182+
/**
183+
* @see https://github.com/prettier/prettier/issues/5817
184+
*/
182185
FunctionExpression(node: any, parent: any) {
183186
if (parent.typeParameters && parent.type === 'Property') {
184187
node.typeParameters = parent.typeParameters;
@@ -196,6 +199,25 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
196199
node.loc.start = Object.assign({}, node.typeParameters.loc.start);
197200
}
198201
},
202+
/**
203+
* Template strings seem to also be affected by the difference in opinion between different parsers in
204+
* @see https://github.com/babel/babel/issues/6681
205+
* @see https://github.com/babel/babel-eslint/blob/master/lib/babylon-to-espree/convertAST.js#L81-L96
206+
*/
207+
TemplateLiteral(node: any) {
208+
for (let j = 0; j < node.quasis.length; j++) {
209+
const q = node.quasis[j];
210+
q.range[0] -= 1;
211+
q.loc.start.column -= 1;
212+
if (q.tail) {
213+
q.range[1] += 1;
214+
q.loc.end.column += 1;
215+
} else {
216+
q.range[1] += 2;
217+
q.loc.end.column += 2;
218+
}
219+
}
220+
},
199221
/**
200222
* TS 3.7: optional chaining
201223
* babel: sets optional property as true/undefined

0 commit comments

Comments
 (0)