From d2b113238af9136d1c874c62b28995b2d01ccc40 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 1 Oct 2023 11:34:04 +0200 Subject: [PATCH 1/3] [JavaScript] Add named context and bailout for `from` This commit... 1. adds a named context `import-export-from-name` 2. adds a bailout in case `from` source literal is missing, so following statements don't break highlighting. --- JavaScript/JavaScript.sublime-syntax | 6 +++++- JavaScript/tests/syntax_test_js_import_export.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index 2a3ab6a44b..f07af688ef 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -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: diff --git a/JavaScript/tests/syntax_test_js_import_export.js b/JavaScript/tests/syntax_test_js_import_export.js index 9b9c1029dd..4e0d16c0bd 100644 --- a/JavaScript/tests/syntax_test_js_import_export.js +++ b/JavaScript/tests/syntax_test_js_import_export.js @@ -161,6 +161,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 @@ -214,7 +220,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"; From 82fb9f5c771a59c88a7db49aeeb6f792f3e0ce74 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 1 Oct 2023 11:38:03 +0200 Subject: [PATCH 2/3] [JavaScript] Add named context for assert/with objects This commit... 1. adds named context for optional object-literals in export/import statements. 2. adds a test case to verify bailout of incomplete statements. --- JavaScript/JavaScript.sublime-syntax | 8 +++++--- JavaScript/tests/syntax_test_js_import_export.js | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index f07af688ef..b3fd39fb29 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -332,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: diff --git a/JavaScript/tests/syntax_test_js_import_export.js b/JavaScript/tests/syntax_test_js_import_export.js index 4e0d16c0bd..9e10d04374 100644 --- a/JavaScript/tests/syntax_test_js_import_export.js +++ b/JavaScript/tests/syntax_test_js_import_export.js @@ -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 From 379c6fbf484bbef6f1ba435b97dddae13d0840bd Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 1 Oct 2023 11:39:49 +0200 Subject: [PATCH 3/3] [JavaScript] Add named context for default exports This commit... 1. adds named context for export-default expressions. 2. adds a test case to verify bailout of incomplete statements. --- JavaScript/JavaScript.sublime-syntax | 9 +++++---- JavaScript/tests/syntax_test_js_import_export.js | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/JavaScript/JavaScript.sublime-syntax b/JavaScript/JavaScript.sublime-syntax index b3fd39fb29..7661d8222b 100644 --- a/JavaScript/JavaScript.sublime-syntax +++ b/JavaScript/JavaScript.sublime-syntax @@ -356,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: @@ -368,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 diff --git a/JavaScript/tests/syntax_test_js_import_export.js b/JavaScript/tests/syntax_test_js_import_export.js index 9e10d04374..2e30337ea9 100644 --- a/JavaScript/tests/syntax_test_js_import_export.js +++ b/JavaScript/tests/syntax_test_js_import_export.js @@ -119,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