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

Commit 9b7e13c

Browse files
authored
feat: ts 3.2 support (#35) (#37)
BREAKING CHANGE: Supported TypeScript version is now 3.2
1 parent ace87ad commit 9b7e13c

File tree

13 files changed

+426
-13
lines changed

13 files changed

+426
-13
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const astNodeTypes = parser.AST_NODE_TYPES;
109109

110110
We will always endeavor to support the latest stable version of TypeScript.
111111

112-
The version of TypeScript currently supported by this parser is `~3.1.1`. This is reflected in the `devDependency` requirement within the package.json file, and it is what the tests will be run against. We have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript.
112+
The version of TypeScript currently supported by this parser is `~3.2.1`. This is reflected in the `devDependency` requirement within the package.json file, and it is what the tests will be run against. We have an open `peerDependency` requirement in order to allow for experimentation on newer/beta versions of TypeScript.
113113

114114
If you use a non-supported version of TypeScript, the parser will log a warning to the console.
115115

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"license": "BSD-2-Clause",
2020
"devDependencies": {
21+
"@babel/parser": "7.1.6",
2122
"@commitlint/cli": "^7.1.2",
2223
"@commitlint/config-conventional": "^7.1.2",
2324
"@commitlint/travis-cli": "^7.1.2",
@@ -29,7 +30,6 @@
2930
"@types/semver": "^5.5.0",
3031
"@types/shelljs": "^0.8.0",
3132
"babel-code-frame": "6.26.0",
32-
"babylon": "7.0.0-beta.39",
3333
"cz-conventional-changelog": "2.1.0",
3434
"glob": "7.1.2",
3535
"husky": "0.14.3",
@@ -41,7 +41,7 @@
4141
"shelljs": "0.8.2",
4242
"travis-deploy-once": "^5.0.8",
4343
"ts-jest": "^23.10.4",
44-
"typescript": "~3.1.1"
44+
"typescript": "~3.2.1"
4545
},
4646
"keywords": [
4747
"ast",

src/ast-node-types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const AST_NODE_TYPES: { [key: string]: string } = {
1212
AssignmentExpression: 'AssignmentExpression',
1313
AssignmentPattern: 'AssignmentPattern',
1414
AwaitExpression: 'AwaitExpression',
15+
BigIntLiteral: 'BigIntLiteral',
1516
BinaryExpression: 'BinaryExpression',
1617
BlockStatement: 'BlockStatement',
1718
BreakStatement: 'BreakStatement',

src/convert.ts

+14
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,20 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
20042004
});
20052005
break;
20062006

2007+
case SyntaxKind.BigIntLiteral: {
2008+
const raw = ast.text.slice(
2009+
(result as any).range[0],
2010+
(result as any).range[1]
2011+
);
2012+
const value = raw.slice(0, -1); // remove suffix `n`
2013+
Object.assign(result, {
2014+
type: AST_NODE_TYPES.BigIntLiteral,
2015+
raw,
2016+
value
2017+
});
2018+
break;
2019+
}
2020+
20072021
case SyntaxKind.RegularExpressionLiteral: {
20082022
const pattern = (node as any).text.slice(
20092023
1,

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

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ let fixturePatternConfigsToTest = [
141141
]
142142
}),
143143

144+
createFixturePatternConfigFor('javascript/bigIntLiterals'),
144145
createFixturePatternConfigFor('javascript/binaryLiterals'),
145146
createFixturePatternConfigFor('javascript/blockBindings'),
146147

tests/ast-alignment/parse.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function createError(message: string, line: number, column: number) {
1515

1616
function parseWithBabylonPluginTypescript(text: string, parserOptions?: any) {
1717
parserOptions = parserOptions || {};
18-
const babylon = require('babylon');
18+
const babylon = require('@babel/parser');
1919
return babylon.parse(
2020
text,
2121
Object.assign(
@@ -28,11 +28,12 @@ function parseWithBabylonPluginTypescript(text: string, parserOptions?: any) {
2828
'jsx',
2929
'typescript',
3030
'objectRestSpread',
31-
'decorators',
31+
'decorators-legacy',
3232
'classProperties',
3333
'asyncGenerators',
3434
'dynamicImport',
35-
'estree'
35+
'estree',
36+
'bigInt'
3637
]
3738
},
3839
parserOptions

tests/ast-alignment/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export function preprocessBabylonAST(ast: any): any {
126126
{
127127
key: 'guardedHandlers',
128128
predicate: always
129+
},
130+
{
131+
key: 'interpreter',
132+
predicate: always
129133
}
130134
]);
131135
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0b1n;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1n;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0x1n;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0o1n;

0 commit comments

Comments
 (0)