Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit e17a604

Browse files
committed
Merge branch 'master' into export-equal
2 parents cbd0437 + edf2727 commit e17a604

14 files changed

+10955
-3227
lines changed

src/ast-node-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const AST_NODE_TYPES: { [key: string]: string } = {
116116
TSExportKeyword: 'TSExportKeyword',
117117
TSExternalModuleReference: 'TSExternalModuleReference',
118118
TSImportType: 'TSImportType',
119+
TSInferType: 'TSInferType',
119120
TSLiteralType: 'TSLiteralType',
120121
TSIndexedAccessType: 'TSIndexedAccessType',
121122
TSIndexSignature: 'TSIndexSignature',
@@ -146,6 +147,7 @@ export const AST_NODE_TYPES: { [key: string]: string } = {
146147
TSStaticKeyword: 'TSStaticKeyword',
147148
TSStringKeyword: 'TSStringKeyword',
148149
TSSymbolKeyword: 'TSSymbolKeyword',
150+
TSThisType: 'TSThisType',
149151
TSTypeAnnotation: 'TSTypeAnnotation',
150152
TSTypeAliasDeclaration: 'TSTypeAliasDeclaration',
151153
TSTypeLiteral: 'TSTypeLiteral',

src/convert.ts

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -282,28 +282,6 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
282282
return classImplementsNode;
283283
}
284284

285-
/**
286-
* Converts a ts.NodeArray of ts.Decorators into an array of ESTreeNode decorators
287-
* @param {ts.NodeArray<ts.Decorator>} decorators A ts.NodeArray of ts.Decorators to be converted
288-
* @returns {ESTreeNode[]} an array of converted ESTreeNode decorators
289-
*/
290-
function convertDecorators(
291-
decorators: ts.NodeArray<ts.Decorator>
292-
): ESTreeNode[] {
293-
if (!decorators || !decorators.length) {
294-
return [];
295-
}
296-
return decorators.map(decorator => {
297-
const expression = convertChild(decorator.expression);
298-
return {
299-
type: AST_NODE_TYPES.Decorator,
300-
range: [decorator.getStart(ast), decorator.end],
301-
loc: nodeUtils.getLoc(decorator, ast),
302-
expression
303-
};
304-
});
305-
}
306-
307285
/**
308286
* Converts an array of ts.Node parameters into an array of ESTreeNode params
309287
* @param {ts.Node[]} parameters An array of ts.Node params to be converted
@@ -319,7 +297,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
319297
return convertedParam;
320298
}
321299
return Object.assign(convertedParam, {
322-
decorators: convertDecorators(param.decorators)
300+
decorators: param.decorators.map(convertChild)
323301
});
324302
});
325303
}
@@ -366,9 +344,8 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
366344
)
367345
: null;
368346
} else if (key === 'decorators') {
369-
const decorators = convertDecorators((node as any).decorators);
370-
if (decorators && decorators.length) {
371-
result.decorators = decorators;
347+
if (node.decorators && node.decorators.length) {
348+
result.decorators = node.decorators.map(convertChild);
372349
}
373350
} else {
374351
if (Array.isArray((node as any)[key])) {
@@ -966,7 +943,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
966943
}
967944

968945
if (node.decorators) {
969-
result.decorators = convertDecorators(node.decorators);
946+
result.decorators = node.decorators.map(convertChild);
970947
}
971948

972949
const accessibility = nodeUtils.getTSNodeAccessibility(node);
@@ -1071,7 +1048,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
10711048
});
10721049

10731050
if (node.decorators) {
1074-
result.decorators = convertDecorators(node.decorators);
1051+
result.decorators = node.decorators.map(convertChild);
10751052
}
10761053

10771054
const accessibility = nodeUtils.getTSNodeAccessibility(node);
@@ -1631,7 +1608,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
16311608
}
16321609

16331610
if (node.decorators) {
1634-
result.decorators = convertDecorators(node.decorators);
1611+
result.decorators = node.decorators.map(convertChild);
16351612
}
16361613

16371614
const filteredMembers = node.members.filter(
@@ -1979,6 +1956,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
19791956
break;
19801957
}
19811958

1959+
case SyntaxKind.Decorator: {
1960+
Object.assign(result, {
1961+
type: AST_NODE_TYPES.Decorator,
1962+
expression: convertChild(node.expression)
1963+
});
1964+
break;
1965+
}
1966+
19821967
// Literals
19831968

19841969
case SyntaxKind.StringLiteral:
@@ -2230,16 +2215,14 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
22302215
type: AST_NODE_TYPES.JSXSpreadAttribute,
22312216
argument: convertChild(node.expression)
22322217
});
2233-
22342218
break;
22352219

2236-
case SyntaxKind.FirstNode: {
2220+
case SyntaxKind.QualifiedName: {
22372221
Object.assign(result, {
22382222
type: AST_NODE_TYPES.TSQualifiedName,
22392223
left: convertChild(node.left),
22402224
right: convertChild(node.right)
22412225
});
2242-
22432226
break;
22442227
}
22452228

@@ -2268,6 +2251,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
22682251
break;
22692252
}
22702253

2254+
case SyntaxKind.ThisType:
22712255
case SyntaxKind.AnyKeyword:
22722256
case SyntaxKind.BigIntKeyword:
22732257
case SyntaxKind.BooleanKeyword:
@@ -2280,7 +2264,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
22802264
case SyntaxKind.VoidKeyword:
22812265
case SyntaxKind.UndefinedKeyword: {
22822266
Object.assign(result, {
2283-
type: `TS${SyntaxKind[node.kind]}`
2267+
type: AST_NODE_TYPES[`TS${SyntaxKind[node.kind]}`]
22842268
});
22852269
break;
22862270
}
@@ -2551,7 +2535,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
25512535
* so we handle them here too.
25522536
*/
25532537
if (node.decorators) {
2554-
result.decorators = convertDecorators(node.decorators);
2538+
result.decorators = node.decorators.map(convertChild);
25552539
}
25562540
if (nodeUtils.hasModifier(SyntaxKind.AbstractKeyword, node)) {
25572541
result.abstract = true;
@@ -2606,7 +2590,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
26062590
* so we handle them here too.
26072591
*/
26082592
if (node.decorators) {
2609-
result.decorators = convertDecorators(node.decorators);
2593+
result.decorators = node.decorators.map(convertChild);
26102594
}
26112595
break;
26122596
}
@@ -2690,6 +2674,13 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
26902674
});
26912675
break;
26922676
}
2677+
case SyntaxKind.InferType: {
2678+
Object.assign(result, {
2679+
type: AST_NODE_TYPES.TSInferType,
2680+
typeParameter: convertChildType(node.typeParameter)
2681+
});
2682+
break;
2683+
}
26932684
case SyntaxKind.ImportEqualsDeclaration: {
26942685
Object.assign(result, {
26952686
type: AST_NODE_TYPES.TSImportEqualsDeclaration,

tests/ast-alignment/fixtures-to-test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,6 @@ let fixturePatternConfigsToTest = [
377377
* tsep: TSBigIntKeyword
378378
*/
379379
'typed-keyword-bigint',
380-
/**
381-
* Awaiting feedback on Babel issue https://github.com/babel/babel/issues/9228
382-
* Babel: BooleanLiteral
383-
* tsep: Literal
384-
*/
385-
'typed-keyword-true',
386-
/**
387-
* Not yet supported in Babel https://github.com/babel/babel/issues/9228
388-
* Babel: BooleanLiteral
389-
* tsep: Literal
390-
*/
391-
'typed-keyword-false',
392380
/**
393381
* Not yet supported in Babel https://github.com/babel/babel/issues/9228
394382
* Directive field is not added to module and namespace

0 commit comments

Comments
 (0)