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

New: Support unknown keyword #3

Merged
merged 3 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions lib/ast-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ module.exports = {
TSTypeReference: "TSTypeReference",
TSUnionType: "TSUnionType",
TSUndefinedKeyword: "TSUndefinedKeyword",
TSUnknownKeyword: "TSUnknownKeyword",
TSVoidKeyword: "TSVoidKeyword",
UnaryExpression: "UnaryExpression",
UpdateExpression: "UpdateExpression",
Expand Down
1 change: 1 addition & 0 deletions lib/node-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ function isTypeKeyword(kind) {
case SyntaxKind.ObjectKeyword:
case SyntaxKind.StringKeyword:
case SyntaxKind.SymbolKeyword:
case SyntaxKind.UnknownKeyword:
case SyntaxKind.VoidKeyword:
return true;
default:
Expand Down
5 changes: 5 additions & 0 deletions tests/ast-alignment/fixtures-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ let fixturePatternConfigsToTest = [
* tsep: DeclareFunction
*/
"declare-function",
/**
* Babylon: TSTypeReference + identifier
* tsep: TSUnknownKeyword
*/
"unknown-type-annotation",
/**
* Other major AST differences (e.g. fundamentally different node types)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let foo: unknown;
205 changes: 205 additions & 0 deletions tests/lib/__snapshots__/typescript.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44884,6 +44884,211 @@ Object {
}
`;

exports[`typescript fixtures/basics/unknown-type-annotation.src 1`] = `
Object {
"body": Array [
Object {
"declarations": Array [
Object {
"id": Object {
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
},
"start": Object {
"column": 4,
"line": 1,
},
},
"name": "foo",
"range": Array [
4,
16,
],
"type": "Identifier",
"typeAnnotation": Object {
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
},
"start": Object {
"column": 7,
"line": 1,
},
},
"range": Array [
7,
16,
],
"type": "TSTypeAnnotation",
"typeAnnotation": Object {
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
},
"start": Object {
"column": 9,
"line": 1,
},
},
"range": Array [
9,
16,
],
"type": "TSUnknownKeyword",
},
},
},
"init": null,
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
},
"start": Object {
"column": 4,
"line": 1,
},
},
"range": Array [
4,
16,
],
"type": "VariableDeclarator",
},
],
"kind": "let",
"loc": Object {
"end": Object {
"column": 17,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
17,
],
"type": "VariableDeclaration",
},
],
"loc": Object {
"end": Object {
"column": 0,
"line": 2,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
18,
],
"sourceType": "script",
"tokens": Array [
Object {
"loc": Object {
"end": Object {
"column": 3,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
3,
],
"type": "Keyword",
"value": "let",
},
Object {
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 4,
"line": 1,
},
},
"range": Array [
4,
7,
],
"type": "Identifier",
"value": "foo",
},
Object {
"loc": Object {
"end": Object {
"column": 8,
"line": 1,
},
"start": Object {
"column": 7,
"line": 1,
},
},
"range": Array [
7,
8,
],
"type": "Punctuator",
"value": ":",
},
Object {
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
},
"start": Object {
"column": 9,
"line": 1,
},
},
"range": Array [
9,
16,
],
"type": "Identifier",
"value": "unknown",
},
Object {
"loc": Object {
"end": Object {
"column": 17,
"line": 1,
},
"start": Object {
"column": 16,
"line": 1,
},
},
"range": Array [
16,
17,
],
"type": "Punctuator",
"value": ";",
},
],
"type": "Program",
}
`;

exports[`typescript fixtures/basics/var-with-definite-assignment.src 1`] = `
Object {
"body": Array [
Expand Down