Skip to content

WIP #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 84 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
b04fc6c
feat(*): Initial commit
JamesHenry Sep 22, 2018
ffb4663
docs(README): Updated docs
JamesHenry Sep 22, 2018
d1d39bf
chore: force LF for tsx files (#11)
uniqueiniquity Sep 26, 2018
678dc60
feat: Support `unknown` keyword (#3)
g-plane Sep 26, 2018
de37f37
chore: lint commit messages (#12)
JamesHenry Sep 27, 2018
027b17b
style: format code and markdown using prettier (#13)
JamesHenry Sep 27, 2018
8a053ee
feat: support TypeScript 3.1 (#14)
outofambit Oct 8, 2018
7d378b1
feat: support shorthand JSX fragments (#15)
wsabransky Oct 8, 2018
c9c6610
fix(ast): fix wrong node type on literal expressions (#4)
g-plane Oct 8, 2018
dd25c09
fix: parse ArrayExpressions correctly (#20)
madbence Oct 28, 2018
991e017
feat: document API and standardize config options (#22)
kaicataldo Oct 31, 2018
32c6ff5
fix(*): brute force initial conversion to TS (#25)
JamesHenry Nov 4, 2018
69c0000
chore: test Node v11 in CI (#29)
kaicataldo Nov 8, 2018
1942eb6
chore: combine basics and ecmaFeatures into javascript tests (#26)
kaicataldo Nov 11, 2018
22f5fb3
feat: offer semantic services alongside AST (#24)
uniqueiniquity Nov 22, 2018
f054806
fix: correct JSXFragment fields (#34)
ikatyang Nov 25, 2018
0842d9b
test: ast alignment tests did not account for javascript rename (#36)
JamesHenry Nov 25, 2018
39b9c90
feat: typed parser return value (#33)
g-plane Nov 26, 2018
1c5025f
feat: add optional global flag to TSModuleDeclaration for global augm…
armano2 Nov 30, 2018
193bfc4
fix: trigger publish
JamesHenry Nov 30, 2018
c961ac1
feat: ts 3.2 support (#35) (#37)
JamesHenry Dec 1, 2018
6bd1fc5
test: replace babylon(beta) with babel/parser (#40)
armano2 Dec 1, 2018
9c64642
chore: regenerate yarn-lock to fix vulnerabilities (#41)
armano2 Dec 5, 2018
6c3d49e
refactor: improve type checking in parser (#43)
armano2 Dec 13, 2018
d5a1ff3
feat: fix issues in AST (#42)
armano2 Dec 19, 2018
542372c
refactor: mark AsteriskAsteriskEquals as assignment operator (#46)
armano2 Dec 19, 2018
91d813f
refactor: remove internal typescript method call with hasModifier (#48)
armano2 Dec 19, 2018
7511e04
chore: add editorconfig (#49)
armano2 Dec 21, 2018
4edb5ca
refactor: improve types in node-utils (#47)
armano2 Dec 21, 2018
cafa43a
fix: non-existent files and custom file extensions (#53)
uniqueiniquity Dec 27, 2018
60f4f25
fix: many missing nodes and better babel alignment (#65)
armano2 Dec 28, 2018
a3da24f
feat: add errorOnTypeScriptSyntaticAndSemanticIssues option (#57)
JamesHenry Dec 28, 2018
3e1f8c7
fix: add missing TSInferType node (#68)
armano2 Jan 1, 2019
12cb5ee
test: refactor omitDeep function to support name changes (#70)
armano2 Jan 1, 2019
d903613
fix: add missing TSThisType no known nodes (#73)
armano2 Jan 1, 2019
90a691b
fix: change incorrect FirstNode to QualifiedName (#76)
armano2 Jan 1, 2019
69f8537
refactor: remove convertDecorators helper (#75)
armano2 Jan 1, 2019
e5158d6
feat: add support and tests for TSAsExpression (#69)
armano2 Jan 1, 2019
3d6480b
feat: add support for export equal declaration (#71)
armano2 Jan 1, 2019
dbddd65
refactor: improve typing (#83)
armano2 Jan 4, 2019
d222238
test: fix issues with collecting coverage from tests (#84)
armano2 Jan 4, 2019
ea218ad
test: add missing test cases for in and for loop (#85)
armano2 Jan 4, 2019
bb89e63
fix: set parent nodes correctly for virtual files (#78)
armano2 Jan 4, 2019
fb8330a
refactor: remove duplicated type ConstructorTypeNode (#81)
armano2 Jan 4, 2019
c975565
BREAKING: add missing TSTypeAssertion node (#79)
armano2 Jan 4, 2019
37260d4
fix: commit message for add missing TSTypeAssertion node (#79)
JamesHenry Jan 4, 2019
e64f656
test: add FixturesTester (#67)
armano2 Jan 4, 2019
5c34695
fix: parsing comments in jsx (#82)
armano2 Jan 4, 2019
53c2223
feat: align call and construct signature declarations (#74)
armano2 Jan 4, 2019
5162b01
feat: add missing TSNamespaceExportDeclaration node (#87)
armano2 Jan 4, 2019
e794e74
test: enable alignment tests for importMeta and add labels test (#88)
armano2 Jan 4, 2019
73d5ff0
refactor: migrate nodeTypes to enum and correct ESTreeComment interfa…
armano2 Jan 4, 2019
4a0624d
fix: correct typo in parser options in word syntactic (#89)
armano2 Jan 5, 2019
0b6afc0
refactor: remove dead code from NamedImports (#90)
armano2 Jan 5, 2019
f282f9c
feat: update TSFunctionType and TSConstructorType nodes (#91)
armano2 Jan 6, 2019
c839243
refactor: improve types and add comments (#92)
armano2 Jan 6, 2019
9c60f35
feat: report on TS 1141, enable semantic errors for AST comparison (#93)
JamesHenry Jan 6, 2019
7bdab68
feat(diagnostics): report on TS 1121 and TS 1200 (#94)
JamesHenry Jan 6, 2019
e535a19
feat(diagnostics): report on TS 1049, TS 1211 and TS 2364 (#95)
JamesHenry Jan 6, 2019
df72f54
feat(diagnostics): report on TS 1014, 1048, 1117, 2462, 17012, 17013 …
JamesHenry Jan 6, 2019
09af3f0
feat(diagnostics): report on TS 1044, 1045, 1097, 1206, 1246 (#97)
JamesHenry Jan 6, 2019
4a3743c
fix: functions without body should be TSDeclareFunctions (#98)
armano2 Jan 6, 2019
78a873e
feat(diagnostics): report on TS 1090, 1173, 1190, 1242, 2369 (#99)
JamesHenry Jan 6, 2019
474e91e
fix: don't mutate original TypeScript AST in converter (#100)
armano2 Jan 6, 2019
fb1e89f
chore: add comments about babel issues (#101)
armano2 Jan 6, 2019
8fdd3cc
fix: parenthesized expressions are not eligible for directive (#103)
JamesHenry Jan 6, 2019
366fbf3
chore: add new notes about PRs in babel (#106)
armano2 Jan 8, 2019
ef703e3
fix: regression in TSTypeParameter node "name" (#111)
armano2 Jan 10, 2019
cd18c94
refactor: simplify assigning directive property to nodes (#105)
armano2 Jan 10, 2019
0c3544f
refactor: unify converting of class and interface heritage (#107)
armano2 Jan 10, 2019
c326435
feat(diagnostics): report on TS 1096 (#110)
armano2 Jan 10, 2019
0f973c5
test: add unsupported test cases for errors (#113)
armano2 Jan 10, 2019
b75b123
feat: rest element should contain information about type annotation (…
armano2 Jan 10, 2019
05ba969
fix: commit message for #108
JamesHenry Jan 10, 2019
5ac295d
feat: update TSMethodSignature node (#104)
armano2 Jan 10, 2019
25c0ace
chore: add codecov (#114)
JamesHenry Jan 11, 2019
44dc229
test: improve workflow for development (#116)
armano2 Jan 11, 2019
89c67d3
refactor: add explicit implementation of TSLiteralType (#117)
armano2 Jan 12, 2019
bd1e2c4
feat: update TSIndexSignature and report on TS1071 (#115)
armano2 Jan 12, 2019
70dcf65
test: add missing test cases for patterns (#119)
armano2 Jan 12, 2019
51394eb
feat: change logic of distinguishing patterns from statements (#118)
armano2 Jan 12, 2019
fb011d4
feat(ast): update TSInterfaceDeclaration and TSClassImplements (#120)
JamesHenry Jan 12, 2019
9c4acbe
refactor: migrate node-utils from commonjs to es6 module (#121)
armano2 Jan 12, 2019
f95c1c8
test: add test cases for broken converting (#123)
armano2 Jan 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions packages/typescript-estree/.codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage:
status:
patch:
default:
target: 90%
project:
default:
target: auto
10 changes: 10 additions & 0 deletions packages/typescript-estree/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
quote_type = single
5 changes: 5 additions & 0 deletions packages/typescript-estree/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
*.js eol=lf
*.ts eol=lf
*.tsx eol=lf
*.yml eol=lf
13 changes: 13 additions & 0 deletions packages/typescript-estree/.github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**What version of TypeScript are you using?**

**What version of `typescript-estree` are you using?**

**What code were you trying to parse?**

```ts
// Put your code here
```

**What did you expect to happen?**

**What actually happened?**
9 changes: 9 additions & 0 deletions packages/typescript-estree/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build
coverage
node_modules
npm-debug.log
_test.js
.DS_Store
.vscode
.idea
dist
1 change: 1 addition & 0 deletions packages/typescript-estree/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
1 change: 1 addition & 0 deletions packages/typescript-estree/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/fixtures/**/*
27 changes: 27 additions & 0 deletions packages/typescript-estree/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: node_js
cache:
yarn: true
directories:
- node_modules
notifications:
email: false
node_js:
- '11'
- '10'
- '9'
- '8'
- '6'
install:
- yarn --ignore-engines
script:
- commitlint-travis
- yarn check-format
- yarn test
- yarn build
- yarn global add codecov
after_success:
- codecov
- yarn travis-deploy-once "yarn semantic-release"
branches:
only:
- master
26 changes: 26 additions & 0 deletions packages/typescript-estree/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TypeScript ESTree

Originally extracted from:

TypeScript ESLint Parser
Copyright JS Foundation and other contributors, https://js.foundation

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139 changes: 139 additions & 0 deletions packages/typescript-estree/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<h1 align="center">TypeScript ESTree</h1>

<p align="center">A parser that converts TypeScript source code into an <a href="https://github.com/estree/estree">ESTree</a>-compatible form</p>

<p align="center">
<a href="https://travis-ci.org/JamesHenry/typescript-estree"><img src="https://img.shields.io/travis/JamesHenry/typescript-estree.svg?style=flat-square" alt="Travis"/></a>
<a href="https://github.com/JamesHenry/typescript-estree/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/typescript-estree.svg?style=flat-square" alt="GitHub license" /></a>
<a href="https://www.npmjs.com/package/typescript-estree"><img src="https://img.shields.io/npm/v/typescript-estree.svg?style=flat-square" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/package/typescript-estree"><img src="https://img.shields.io/npm/dt/typescript-estree.svg?style=flat-square" alt="NPM Downloads" /></a>
<a href="http://commitizen.github.io/cz-cli/"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" /></a>
<a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square" alt="semantic-release" /></a>
</p>

<br>

## About

This parser is somewhat generic and robust, and could be used to power any use-case which requires taking TypeScript source code and producing an ESTree-compatible AST.

In fact, it is already used within these hyper-popular open-source projects to power their TypeScript support:

- [ESLint](https://eslint.org), the pluggable linting utility for JavaScript and JSX
- See [typescript-eslint-parser](https://github.com/eslint/typescript-eslint-parser) for more details
- [Prettier](https://prettier.io), an opinionated code formatter

## Installation

```
npm install --save typescript-estree
```

## API

### parse(code, options)

Parses the given string of code with the options provided and returns an ESTree-compatible AST. The options object has the following properties:

```javascript
{
// attach range information to each node
range: false,

// attach line/column location information to each node
loc: false,

// create a top-level tokens array containing all tokens
tokens: false,

// create a top-level comments array containing all comments
comment: false,

// enable parsing JSX. For more details, see https://www.typescriptlang.org/docs/handbook/jsx.html
jsx: false,

/*
* The JSX AST changed the node type for string literals
* inside a JSX Element from `Literal` to `JSXText`.
* When value is `true`, these nodes will be parsed as type `JSXText`.
* When value is `false`, these nodes will be parsed as type `Literal`.
*/
useJSXTextNode: false,

// Cause the parser to error if it encounters an unknown AST node type (useful for testing)
errorOnUnknownASTType: false,

/*
* Allows overriding of function used for logging.
* When value is `false`, no logging will occur.
* When value is not provided, `console.log()` will be used.
*/
loggerFn: undefined
}
```

Example usage:

```javascript
const parser = require('typescript-estree');
const code = `const hello: string = 'world';`;
const ast = parser.parse(code, {
range: true,
loc: true
});
```

### version

Exposes the current version of typescript-estree as specified in package.json.

Example usage:

```javascript
const parser = require('typescript-estree');
const version = parser.version;
```

### AST_NODE_TYPES

Exposes an object that contains the AST node types produced by the parser.

Example usage:

```javascript
const parser = require('typescript-estree');
const astNodeTypes = parser.AST_NODE_TYPES;
```

## Supported TypeScript Version

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

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.

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

**Please ensure that you are using a supported version before submitting any issues/bug reports.**

## Reporting Issues

Please check the current list of open and known issues and ensure the issue has not been reported before. When creating a new issue provide as much information about your environment as possible. This includes:

- TypeScript version
- The `typescript-estree` version

## AST Alignment Tests

A couple of years after work on this parser began, the TypeScript Team at Microsoft began [officially supporting TypeScript parsing via Babel](https://blogs.msdn.microsoft.com/typescript/2018/08/27/typescript-and-babel-7/).

I work closely with TypeScript Team and we are gradually aliging the AST of this project with the one produced by Babel's parser. To that end, I have created a full test harness to compare the ASTs of the two projects which runs on every PR, please see the code for more details.

## Build/Test Commands

- `npm test` - run all tests
- `npm run unit-tests` - run only unit tests
- `npm run ast-alignment-tests` - run only Babylon AST alignment tests

## License

TypeScript ESTree inherits from the the original TypeScript ESLint Parser license, as the majority of the work began there. It is licensed under a permissive BSD 2-clause license.
13 changes: 13 additions & 0 deletions packages/typescript-estree/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = {
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testRegex: './tests/(lib/.*\\.(jsx?|tsx?)|ast-alignment/spec\\.ts)$',
collectCoverage: false,
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coverageReporters: ['text-summary', 'lcov']
};
90 changes: 90 additions & 0 deletions packages/typescript-estree/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"name": "typescript-estree",
"description": "A parser that converts TypeScript source code into an ESTree compatible form",
"homepage": "https://github.com/JamesHenry/typescript-estree",
"main": "dist/parser.js",
"version": "0.0.0-development",
"files": [
"dist",
"README.md",
"LICENSE"
],
"engines": {
"node": ">=6.14.0"
},
"repository": "JamesHenry/typescript-estree",
"bugs": {
"url": "https://github.com/JamesHenry/typescript-estree/issues"
},
"license": "BSD-2-Clause",
"devDependencies": {
"@babel/code-frame": "7.0.0",
"@babel/parser": "7.2.3",
"@commitlint/cli": "^7.1.2",
"@commitlint/config-conventional": "^7.1.2",
"@commitlint/travis-cli": "^7.1.2",
"@types/babel-code-frame": "^6.20.1",
"@types/jest": "^23.3.9",
"@types/lodash.isplainobject": "^4.0.4",
"@types/lodash.unescape": "^4.0.4",
"@types/node": "^10.12.2",
"@types/semver": "^5.5.0",
"@types/shelljs": "^0.8.0",
"cz-conventional-changelog": "2.1.0",
"glob": "7.1.2",
"husky": "0.14.3",
"jest": "23.6.0",
"lint-staged": "7.3.0",
"lodash.isplainobject": "4.0.6",
"prettier": "^1.14.3",
"semantic-release": "^15.9.16",
"shelljs": "0.8.2",
"travis-deploy-once": "^5.0.8",
"ts-jest": "^23.10.4",
"typescript": "~3.2.1"
},
"keywords": [
"ast",
"estree",
"ecmascript",
"javascript",
"typescript",
"parser",
"syntax"
],
"scripts": {
"build": "tsc",
"test": "jest --coverage",
"unit-tests": "jest \"./tests/lib/.*\"",
"ast-alignment-tests": "jest spec.ts",
"precommit": "npm test && lint-staged",
"cz": "git-cz",
"commitmsg": "commitlint -E GIT_PARAMS",
"check-format": "prettier --list-different \"./**/*.{ts,js,json,md}\"",
"semantic-release": "semantic-release",
"travis-deploy-once": "travis-deploy-once"
},
"dependencies": {
"lodash.unescape": "4.0.1",
"semver": "5.5.0"
},
"peerDependencies": {
"typescript": "*"
},
"lint-staged": {
"*.{ts,js,json,md}": [
"prettier --write",
"git add"
]
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
}
}
Loading