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

Breaking: Updates to AST node types of some TSNodes (fixes #386) #388

Merged
merged 3 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,26 @@ Issues and pull requests will be triaged and responded to as quickly as possible

## Build Commands

* `npm test` - run all linting and tests
* `npm run lint` - run all linting
* To run all of the linting, unit tests and AST alignment tests with Babylon:
```
npm test
```

* To run just the linting:
```
npm run lint
```

* To run just the unit tests:
```
npm run jest
```

* To run just the AST alignment tests with Babylon:
```
npm run ast-alignment-tests
```

## License

TypeScript ESLint Parser is licensed under a permissive BSD 2-clause license.

10 changes: 4 additions & 6 deletions lib/ast-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ module.exports = {
ThisExpression: "ThisExpression",
ThrowStatement: "ThrowStatement",
TryStatement: "TryStatement",

/**
* TS-prefixed nodes
*/
Expand Down Expand Up @@ -140,17 +139,16 @@ module.exports = {
TSStaticKeyword: "TSStaticKeyword",
TSStringKeyword: "TSStringKeyword",
TSSymbolKeyword: "TSSymbolKeyword",
TSTypeAnnotation: "TSTypeAnnotation",
TSTypeLiteral: "TSTypeLiteral",
TSTypeParameter: "TSTypeParameter",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this will conflict with TypeParameters that were already being copied over :(

Example with mapped types:

var x: { [A in keyof B]?: any };

Ref: prettier/prettier#1393

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your patience on this @existentialism, I have a fix for that in prettier and have opened a PR here: prettier/prettier#3455

TSTypeParameterDeclaration: "TSTypeParameterDeclaration",
TSTypeParameterInstantiation: "TSTypeParameterInstantiation",
TSTypePredicate: "TSTypePredicate",
TSTypeReference: "TSTypeReference",
TSUnionType: "TSUnionType",
TSUndefinedKeyword: "TSUndefinedKeyword",
TSVoidKeyword: "TSVoidKeyword",

TypeAnnotation: "TypeAnnotation",
TypeParameter: "TypeParameter",
TypeParameterDeclaration: "TypeParameterDeclaration",
TypeParameterInstantiation: "TypeParameterInstantiation",
UnaryExpression: "UnaryExpression",
UpdateExpression: "UpdateExpression",
VariableDeclaration: "VariableDeclaration",
Expand Down
8 changes: 4 additions & 4 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = function convert(config) {
const annotationStartCol = child.getFullStart() - 1;
const loc = nodeUtils.getLocFor(annotationStartCol, child.end, ast);
return {
type: AST_NODE_TYPES.TypeAnnotation,
type: AST_NODE_TYPES.TSTypeAnnotation,
loc,
range: [annotationStartCol, child.end],
typeAnnotation: annotation
Expand All @@ -107,7 +107,7 @@ module.exports = function convert(config) {
const greaterThanToken = nodeUtils.findNextToken(lastTypeArgument, ast);

return {
type: AST_NODE_TYPES.TypeParameterInstantiation,
type: AST_NODE_TYPES.TSTypeParameterInstantiation,
range: [
firstTypeArgument.pos - 1,
greaterThanToken.end
Expand Down Expand Up @@ -152,7 +152,7 @@ module.exports = function convert(config) {
const greaterThanToken = nodeUtils.findNextToken(lastTypeParameter, ast);

return {
type: AST_NODE_TYPES.TypeParameterDeclaration,
type: AST_NODE_TYPES.TSTypeParameterDeclaration,
range: [
firstTypeParameter.pos - 1,
greaterThanToken.end
Expand All @@ -170,7 +170,7 @@ module.exports = function convert(config) {
: typeParameter.default;

return {
type: AST_NODE_TYPES.TypeParameter,
type: AST_NODE_TYPES.TSTypeParameter,
range: [
typeParameter.getStart(),
typeParameter.getEnd()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "BSD-2-Clause",
"devDependencies": {
"babel-code-frame": "^6.26.0",
"babylon": "7.0.0-beta.24",
"babylon": "^7.0.0-beta.25",
"eslint": "4.6.1",
"eslint-config-eslint": "4.0.0",
"eslint-plugin-node": "5.1.1",
Expand Down
Loading