Skip to content

Commit

Permalink
test(typescript-estree): alignment tests for TemplateLiteral node (#1421
Browse files Browse the repository at this point in the history
)
  • Loading branch information
armano2 authored and bradzacher committed Jan 9, 2020
1 parent 6c35de6 commit 42b0fcc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
23 changes: 7 additions & 16 deletions packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
Expand Up @@ -125,21 +125,18 @@ jsxFilesWithKnownIssues.push('invalid-no-tag-name');

tester.addFixturePatternConfig('javascript/basics');

tester.addFixturePatternConfig('comments', {
tester.addFixturePatternConfig('comments');

tester.addFixturePatternConfig('javascript/templateStrings', {
ignore: [
/**
* Template strings seem to also be affected by the difference in opinion between different parsers in:
* https://github.com/babel/babel/issues/6681
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
* SyntaxError: Invalid escape sequence in template
*/
'no-comment-template', // Purely AST diffs
'template-string-block', // Purely AST diffs
'error-octal-literal',
],
});

tester.addFixturePatternConfig('javascript/templateStrings', {
ignore: ['**/*'],
});

tester.addFixturePatternConfig('javascript/arrayLiteral');

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

tester.addFixturePatternConfig('typescript/expressions', {
fileType: 'ts',
ignore: [
/**
* there is difference in range between babel and ts-estree
*/
'tagged-template-expression-type-arguments',
],
});

tester.addFixturePatternConfig('typescript/errorRecovery', {
fileType: 'ts',
ignore: [
/**
* [TS-ESTREE ERRORED, BUT BABEL DID NOT]
* [BABEL ERRORED, BUT TS-ESTREE DID NOT]
* TODO: enable error code TS1019: An index signature parameter cannot have a question mark.
*/
'interface-with-optional-index-signature',
Expand Down
24 changes: 23 additions & 1 deletion packages/typescript-estree/tests/ast-alignment/utils.ts
Expand Up @@ -130,6 +130,7 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
/**
* We want this node to be different
* @see https://github.com/JamesHenry/typescript-estree/issues/109
* @see https://github.com/prettier/prettier/pull/5728
*/
TSTypeParameter(node: any) {
if (node.name) {
Expand Down Expand Up @@ -178,7 +179,9 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
node.type = 'TSClassImplements';
}
},
// https://github.com/prettier/prettier/issues/5817
/**
* @see https://github.com/prettier/prettier/issues/5817
*/
FunctionExpression(node: any, parent: any) {
if (parent.typeParameters && parent.type === 'Property') {
node.typeParameters = parent.typeParameters;
Expand All @@ -196,6 +199,25 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any {
node.loc.start = Object.assign({}, node.typeParameters.loc.start);
}
},
/**
* Template strings seem to also be affected by the difference in opinion between different parsers in
* @see https://github.com/babel/babel/issues/6681
* @see https://github.com/babel/babel-eslint/blob/master/lib/babylon-to-espree/convertAST.js#L81-L96
*/
TemplateLiteral(node: any) {
for (let j = 0; j < node.quasis.length; j++) {
const q = node.quasis[j];
q.range[0] -= 1;
q.loc.start.column -= 1;
if (q.tail) {
q.range[1] += 1;
q.loc.end.column += 1;
} else {
q.range[1] += 2;
q.loc.end.column += 2;
}
}
},
/**
* TS 3.7: optional chaining
* babel: sets optional property as true/undefined
Expand Down

0 comments on commit 42b0fcc

Please sign in to comment.