Skip to content

Commit

Permalink
Merge pull request #3 from deathaxe/pr/javascript/cleanup-imports
Browse files Browse the repository at this point in the history
Add some named contexts and bailouts
  • Loading branch information
Thom1729 authored Oct 1, 2023
2 parents 78249eb + 379c6fb commit c4cd57b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
23 changes: 15 additions & 8 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ contexts:
import-export-from:
- match: 'from{{identifier_break}}'
scope: keyword.control.import-export.js
set: literal-string
set: import-export-from-name
- include: else-pop

import-export-from-name:
- include: literal-string
- include: else-pop

import-string-or-items:
Expand Down Expand Up @@ -328,9 +332,11 @@ contexts:
import-export-assert:
- match: (?:assert|with){{identifier_break}}
scope: keyword.control.import-export.js
set:
- include: object-literal
- include: else-pop
set: import-export-object
- include: else-pop

import-export-object:
- include: object-literal
- include: else-pop

export-statement:
Expand All @@ -350,10 +356,7 @@ contexts:

- match: default{{identifier_break}}
scope: keyword.control.import-export.js
set:
- include: declaration
- match: (?=\S)
set: expression-statement
set: export-default

- match: (?=\S)
set:
Expand All @@ -362,6 +365,10 @@ contexts:
- import-export-from
- import-export-item

export-default:
- include: declaration
- include: expression-statement

statements:
- match: '\)|\}|\]'
scope: invalid.illegal.stray-bracket-end.js
Expand Down
22 changes: 22 additions & 0 deletions JavaScript/tests/syntax_test_js_import_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import thing, {identifier as otherIdentifier}, * as otherName from "otherplace";
import 'module';
// ^^^^^^^^^^^^^ meta.import

import foo from 'bar' assert // incomplete!
//^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.import.js

import foo from 'bar' assert { type: "json" };
// <- meta.import.js keyword.control.import-export.js
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.import.js
//^^^^ keyword.control.import-export.js
// ^^^ variable.other.readwrite.js
Expand Down Expand Up @@ -115,7 +119,14 @@ export class Foo {};
// ^^^^^^^^^^^^ meta.class
// ^ punctuation.terminator.statement.empty

export default
// <- meta.export.js keyword.control.import-export.js
//^^^^^^^^^^^^^ meta.export.js
//^^^^ keyword.control.import-export.js
// ^^^^^^^ keyword.control.import-export.js

export default expression;
// <- meta.export.js keyword.control.import-export.js
//^^^^^^^^^^^^^^^^^^^^^^^^ meta.export
//^ keyword.control.import-export
// ^ keyword.control.import-export
Expand Down Expand Up @@ -161,6 +172,12 @@ export { name1 as default };
// ^ keyword.control.import-export
// ^ keyword.control.import-export

export * from // incomplete, missing source!
//^^^^^^^^^^^^ meta.export.js
//^^^^ keyword.control.import-export.js
// ^ constant.other.wildcard.asterisk.js
// ^^^^ keyword.control.import-export.js

export * from "./othermod";
//^^^^^^^^^^^^^^^^^^^^^^^^^ meta.export
//^ keyword.control.import-export
Expand Down Expand Up @@ -214,7 +231,12 @@ export { member as
let from;
// ^^^^ variable.other.readwrite.js

import from from // incomplete, missing source!
// <- meta.import.js keyword.control.import-export.js
// ^^^^ variable.other.readwrite.js

import from from "./othermod";
// <- meta.import.js keyword.control.import-export.js
// ^^^^ variable.other.readwrite.js

import { from } from "./othermod";
Expand Down

0 comments on commit c4cd57b

Please sign in to comment.