Skip to content

Commit

Permalink
[JavaScript] [TypeScript] Clean up export code and support more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Thom1729 committed Sep 29, 2023
1 parent e4e5273 commit 6071937
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 48 deletions.
61 changes: 24 additions & 37 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,6 @@ contexts:
fail: import-statement
- include: else-pop

export-statement:
- match: export{{identifier_break}}
scope: keyword.control.import-export.js
set:
- export-meta
- export-extended

import-meta:
- meta_include_prototype: false
- meta_scope: meta.import.js
Expand All @@ -272,15 +265,17 @@ contexts:
import-export-alias:
- match: as{{identifier_break}}
scope: keyword.control.import-export.js
set:
- match: default{{identifier_break}}
scope: keyword.control.import-export.js
pop: 1
- match: '{{identifier_name}}'
scope: variable.other.readwrite.js
pop: 1
- include: literal-string
- include: else-pop
set: import-export-name
- include: else-pop

import-export-name:
- match: default{{identifier_break}}
scope: keyword.control.import-export.js
pop: 1
- match: '{{identifier_name}}'
scope: variable.other.readwrite.js
pop: 1
- include: literal-string
- include: else-pop

import-export-from:
Expand Down Expand Up @@ -340,12 +335,19 @@ contexts:
- include: else-pop
- include: else-pop

export-statement:
- match: export{{identifier_break}}
scope: keyword.control.import-export.js
set:
- export-meta
- export-body

export-meta:
- meta_include_prototype: false
- meta_scope: meta.export.js
- include: immediately-pop

export-extended:
export-body:
- include: declaration

- match: 'default{{identifier_break}}'
Expand All @@ -359,28 +361,15 @@ contexts:
set:
- expect-semicolon
- import-export-from
- export-list
- import-export-alias
- export-item

export-list:
- match: ','
scope: punctuation.separator.comma.js
push:
- import-export-alias
- export-item
- include: else-pop

export-item:
- match: '\{'
scope: punctuation.section.block.begin.js
set: export-brace
- match: '{{non_reserved_identifier}}'
scope: variable.other.readwrite.js
pop: 1
- match: '\*'
scope: constant.other.js
pop: 1
set: import-export-alias
- include: else-pop

export-brace:
Expand All @@ -389,12 +378,10 @@ contexts:
- match: '\}'
scope: punctuation.section.block.end.js
pop: 1
- match: '{{identifier_name}}'
scope: variable.other.readwrite.js
push: import-export-alias
- match: '\*'
scope: constant.other.js
push: import-export-alias
- match: (?={{identifier_start}}|'|")
push:
- import-export-alias
- import-export-name
- include: else-pop

statements:
Expand Down
21 changes: 20 additions & 1 deletion JavaScript/TypeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,21 @@ contexts:
- include: comments
- include: else-pop

export-extended:
export-body:
- meta_prepend: true

- match: as{{identifier_break}}
scope: storage.modifier.js
set:
- expect-semicolon
- ts-export-as-namespace

- match: (?=type{{identifier_break}})
branch_point: ts-export-type-from
branch:
- ts-export-type-from
- ts-type-declaration

ts-export-as-namespace:
- match: namespace{{identifier_break}}
scope: keyword.declaration.js
Expand All @@ -85,6 +92,18 @@ contexts:
- ts-namespace-name
- include: else-pop

ts-export-type-from:
- match: type{{identifier_break}}
scope: keyword.control.import-export.js
set:
- match: (?=\{|\*)
set:
- expect-semicolon
- import-export-from
- export-item
- match: (?=\S)
fail: ts-export-type-from

parenthesized-expression:
- match: \(
scope: punctuation.section.group.begin.js
Expand Down
14 changes: 6 additions & 8 deletions JavaScript/tests/syntax_test_js_import_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ import;
import;/**/
// ^ - meta.import

export { name1, name2 as name3, name4 as '+', name5 as "+" };
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.export
export { name1, name2 as name3, name4 as '+', 'name5' as "+" };
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.export
//^ keyword.control.import-export
// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block
// ^ punctuation.separator.comma
// ^^ keyword.control.import-export
// ^^ keyword.control.import-export
// ^^^ meta.string string.quoted.single
// ^^ keyword.control.import-export
// ^^^ meta.string string.quoted.double
// ^^^^^^^ meta.string string.quoted.single
// ^^ keyword.control.import-export
// ^^^ meta.string string.quoted.double

export let name1, name2;
//^^^^^^^^^^^^^^^^^^^^^^ meta.export
Expand Down Expand Up @@ -215,9 +216,6 @@ import from from "./othermod";
import { from } from "./othermod";
// ^^^^ variable.other.readwrite.js

export from from "./othermod";
// ^^^^ variable.other.readwrite.js

export { from } from "./othermod";
// ^^^^ variable.other.readwrite.js

Expand Down
31 changes: 29 additions & 2 deletions JavaScript/tests/syntax_test_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,37 @@ import foo;
// ^ punctuation.terminator.statement

export type T = any;
// ^^^^^^^^^^^^^^^^^^^ meta.export
// ^^^^^^^^^^^^^^^^^^^^ meta.export
// ^^^^^^ keyword.control.import-export
// ^^^^^^^^^^^^ meta.type-alias
// ^ punctuation.terminator.statement.empty - meta.export
// ^ punctuation.terminator.statement - punctuation.terminator.statement.empty

export type { T } from 'somewhere';
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.export
// ^^^^^^ keyword.control.import-export
// ^^^^ keyword.control.import-export
// ^^^^^ meta.block
// ^ punctuation.section.block.begin
// ^ variable.other.readwrite
// ^ punctuation.section.block.end
// ^^^^ keyword.control.import-export
// ^^^^^^^^^^^ meta.string string.quoted.single
// ^ punctuation.definition.string.begin
// ^ punctuation.definition.string.end
// ^ punctuation.terminator.statement - punctuation.terminator.statement.empty

export type * as T from 'somewhere';
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.export
// ^^^^^^ keyword.control.import-export
// ^^^^ keyword.control.import-export
// ^ constant.other
// ^^ keyword.control.import-export
// ^ variable.other.readwrite
// ^^^^ keyword.control.import-export
// ^^^^^^^^^^^ meta.string string.quoted.single
// ^ punctuation.definition.string.begin
// ^ punctuation.definition.string.end
// ^ punctuation.terminator.statement - punctuation.terminator.statement.empty

export interface Foo {}
// ^^^^^^^^^^^^^^^^^^^^^^^ meta.export
Expand Down

0 comments on commit 6071937

Please sign in to comment.