Skip to content

Commit

Permalink
feat(parser): move hashbang out of "next" option
Browse files Browse the repository at this point in the history
Hashbang is a finished proposal. https://github.com/tc39/proposals/blob/main/finished-proposals.md

BREAKING CHANGE: hashbang now works without "next" option.
  • Loading branch information
3cp committed Jul 25, 2024
1 parent 77d3fdc commit e2f28fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
## ESNext features

- [Decorators](https://github.com/tc39/proposal-decorators)
- [Class Public Instance Fields & Private Instance Fields](https://github.com/tc39/proposal-class-fields)
- [Hashbang grammar](https://github.com/tc39/proposal-hashbang)
- [Private methods](https://github.com/tc39/proposal-private-methods)
- [Static class fields and private static methods](https://github.com/tc39/proposal-static-class-features/)
- [Import Attributes](https://github.com/tc39/proposal-import-attributes)
- [JSON Modules](https://github.com/tc39/proposal-json-modules)

**Note:** These features need to be enabled with the `next` option.

Expand Down
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export function parseSource(source: string, options: Options | void, context: Co
const parser = create(source, sourceFile, onComment, onToken, onInsertedSemicolon);

// See: https://github.com/tc39/proposal-hashbang
if (context & Context.OptionsNext) skipHashBang(parser);
skipHashBang(parser);

const scope: ScopeState | undefined = context & Context.OptionsLexical ? createScope() : void 0;

Expand Down
34 changes: 17 additions & 17 deletions test/parser/next/hashbang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import { parseSource } from '../../../src/parser';

describe('Next - Hashbang grammar', () => {
fail('Next - Hashbang grammar (fail)', [
['\x20#!', Context.OptionsNext],
['\r\n#!\n', Context.OptionsNext],
['\r#!\n', Context.OptionsNext],
['\n#!', Context.OptionsNext],
['\x20#!', Context.None],
['\r\n#!\n', Context.None],
['\r#!\n', Context.None],
['\n#!', Context.None],
['\\u0023!', Context.OptionsWebCompat],
['#\\u0021\n', Context.None],
['#\\u{21}\n', Context.None],
['#\\041\n', Context.None],
['#\\u{21}', Context.None],
['\\x23!', Context.OptionsNext],
[`#!\n#!`, Context.OptionsNext],
['/*\n*/#!', Context.OptionsNext],
['"use strict"\n#!', Context.OptionsNext],
['\\u0023\\u0021', Context.OptionsNext],
[';#!', Context.OptionsNext],
['//\n#!', Context.OptionsNext],
['{ #! }', Context.OptionsNext],
['#\n/*\n\n*/', Context.OptionsNext],
['function fn(a = #\\u0021\n) {}', Context.OptionsNext],
['() => #\n/*\n\n*/', Context.OptionsNext]
['\\x23!', Context.None],
[`#!\n#!`, Context.None],
['/*\n*/#!', Context.None],
['"use strict"\n#!', Context.None],
['\\u0023\\u0021', Context.None],
[';#!', Context.None],
['//\n#!', Context.None],
['{ #! }', Context.None],
['#\n/*\n\n*/', Context.None],
['function fn(a = #\\u0021\n) {}', Context.None],
['() => #\n/*\n\n*/', Context.None]
]);

for (const arg of [
Expand All @@ -45,15 +45,15 @@ describe('Next - Hashbang grammar', () => {
]) {
it(`${arg}`, () => {
t.doesNotThrow(() => {
parseSource(`${arg}`, undefined, Context.OptionsNext);
parseSource(`${arg}`, undefined, Context.None);
});
});

// Should pass in strict mode and module code

it(`${arg}`, () => {
t.doesNotThrow(() => {
parseSource(`${arg}`, undefined, Context.OptionsNext | Context.Strict | Context.Module);
parseSource(`${arg}`, undefined, Context.Strict | Context.Module);
});
});
}
Expand Down

0 comments on commit e2f28fc

Please sign in to comment.