-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support ES2023 and hashbangs (#556)
* feat: Support ES2023 and hashbangs * Improve comment * Update README with ES2023 feature support * Update ecmaVersion test runner to include comments By default, the `ecmaVersion` test runner was not asking the parser for comments. Now, when the source filename contains `comment`, it sets `comment: true` and includes comments in the expected result. This extends the precedent set by filenames containing strings like `"non-strict"`, `"edge-cases"`, `"modules"`, and a few others, all of which put the test runner in slightly different modes. * Define custom Hashbang comment type Reviewers asked for the hashbang comment to have a type distinct from `"Line"` [1]. ESLint already handles hashbangs internally, and removing its custom handling would break backwards compatibility. The name is therefore up to whatever non-ESLint users of Espree would expect. [2] The hashbang grammar proposal already addressed this choice directly [3], so this commit defines the type as `"Hashbang"` to match the proposal. [1]: #556 (comment) [2]: #556 (comment) [3]: https://github.com/tc39/proposal-hashbang#why-hashbang-instead-of-shebang
- Loading branch information
Showing
10 changed files
with
111 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
tests/fixtures/ecma-version/14/hashbang/invalid-comment-not-at-beginning.result.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
"index": 15, | ||
"lineNumber": 2, | ||
"column": 2, | ||
"message": "Unexpected character '!'" | ||
}; |
2 changes: 2 additions & 0 deletions
2
tests/fixtures/ecma-version/14/hashbang/invalid-comment-not-at-beginning.src.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'use strict'; | ||
#!/usr/bin/env node |
40 changes: 40 additions & 0 deletions
40
tests/fixtures/ecma-version/14/hashbang/valid-comment-at-beginning.result.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export default { | ||
"type": "Program", | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 0 | ||
} | ||
}, | ||
"range": [ | ||
0, | ||
20 | ||
], | ||
"body": [], | ||
"sourceType": "script", | ||
"comments": [ | ||
{ | ||
"type": "Hashbang", | ||
"value": "/usr/bin/env node", | ||
"range": [ | ||
0, | ||
19 | ||
], | ||
"loc": { | ||
"start": { | ||
"line": 1, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 19 | ||
} | ||
} | ||
} | ||
], | ||
"tokens": [] | ||
}; |
1 change: 1 addition & 0 deletions
1
tests/fixtures/ecma-version/14/hashbang/valid-comment-at-beginning.src.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#!/usr/bin/env node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters