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

Commit

Permalink
feat: Support unknown keyword (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and JamesHenry committed Sep 27, 2018
1 parent c955e0d commit aa8496e
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ast-node-types.js
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
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
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
@@ -0,0 +1 @@
let foo: unknown;
205 changes: 205 additions & 0 deletions tests/lib/__snapshots__/typescript.js.snap
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

0 comments on commit aa8496e

Please sign in to comment.