Skip to content

Commit 36cc10c

Browse files
committed
Fix non-null assertion breaking js value termination
This commit embeds JavaScript into string values assuming nested quotation marks not being supported to ensure string value termination.
1 parent f963b0c commit 36cc10c

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

Vue Component.sublime-syntax

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -829,35 +829,41 @@ contexts:
829829
- meta_content_scope: meta.directive.vue
830830
- match: =
831831
scope: meta.directive.vue punctuation.separator.key-value.vue
832-
set: vue-directive-value
832+
set:
833+
- immediately-pop
834+
- vue-directive-value
833835
- include: else-pop
834836

835837
vue-directive-value:
836-
- meta_content_scope: meta.directive.vue
837838
- match: \"
838-
scope: string.quoted.double.vue punctuation.definition.string.begin.vue
839-
set: vue-directive-double-quoted-value
840-
- match: \'
841-
scope: string.quoted.single.vue punctuation.definition.string.begin.vue
842-
set: vue-directive-single-quoted-value
843-
- include: else-pop
844-
845-
vue-directive-double-quoted-value:
846-
- meta_include_prototype: false
847-
- meta_scope: meta.directive.value.vue meta.string.vue
848-
- meta_content_scope: meta.embedded.expression.vue source.js.embedded.vue
849-
- match: \"
850-
scope: string.quoted.double.vue punctuation.definition.string.end.vue
839+
scope:
840+
meta.directive.value.vue meta.string.vue
841+
string.quoted.double.vue punctuation.definition.string.begin.vue
842+
embed: javascript-expressions
843+
embed_scope:
844+
meta.directive.value.vue meta.string.vue
845+
meta.embedded.expression.vue source.js.embedded.vue
846+
escape: \"
847+
escape_captures:
848+
0: meta.directive.value.vue meta.string.vue
849+
string.quoted.double.vue punctuation.definition.string.end.vue
851850
pop: 1
852-
- match: (?=\S)
853-
push: scope:source.js#expression
854-
855-
vue-directive-single-quoted-value:
856-
- meta_include_prototype: false
857-
- meta_scope: meta.directive.value.vue meta.string.vue
858-
- meta_content_scope: meta.embedded.expression.vue source.js.embedded.vue
859851
- match: \'
860-
scope: string.quoted.single.vue punctuation.definition.string.end.vue
852+
scope:
853+
meta.directive.value.vue meta.string.vue
854+
string.quoted.single.vue punctuation.definition.string.begin.vue
855+
embed: javascript-expressions
856+
embed_scope:
857+
meta.directive.value.vue meta.string.vue
858+
meta.embedded.expression.vue source.js.embedded.vue
859+
escape: \'
860+
escape_captures:
861+
0: meta.directive.value.vue meta.string.vue
862+
string.quoted.single.vue punctuation.definition.string.end.vue
861863
pop: 1
864+
- include: else-pop
865+
866+
javascript-expressions:
867+
# required until ST4176
862868
- match: (?=\S)
863869
push: scope:source.js#expression

tests/syntax_test_directive.vue

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,6 @@
247247
// ^^^^^^^ meta.string.js string.quoted.double.js
248248
// ^ keyword.operator.ternary.js
249249
// ^^^^^ meta.string.js string.quoted.double.js
250-
width: `'${width + "double" + 'single' + quoted}px'` // note the single quotes!
251-
// ^^ meta.string string.quoted.other.js
252-
// ^^^^^^^^^^ meta.string meta.interpolation.js - string
253-
// ^^^^^^^^ meta.interpolation.js string.quoted.double.js
254-
// ^^^ meta.string meta.interpolation.js - string
255-
// ^^^^^^^^ meta.interpolation.js string.quoted.single.js
256-
// ^^^^^^^^^^ meta.string meta.interpolation.js - string
257-
// ^^^^ meta.string string.quoted.other.js
258250
}'>
259251
//^^^ meta.directive.value.vue meta.string.vue meta.embedded.expression.vue source.js.embedded.vue meta.mapping.js
260252
// ^ meta.directive.value.vue meta.string.vue string.quoted.single.vue punctuation.definition.string.end.vue
@@ -385,3 +377,22 @@
385377
// ^ meta.tag.template.begin.html meta.directive.vue
386378
// ^ meta.tag.template.begin.html - meta.directive
387379
// ^ - meta.tag
380+
381+
382+
// https://github.com/SublimeText/Vue/issues/48
383+
384+
<Component :name="obj?.name!" />
385+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.tag.other.html
386+
// ^ punctuation.definition.tag.begin.html
387+
// ^^^^^^^^^ entity.name.tag.other.html
388+
// ^ meta.directive.vue keyword.other.directive.vue
389+
// ^^^^ meta.directive.parameter.vue entity.other.attribute-name.vue
390+
// ^ meta.directive.vue punctuation.separator.key-value.vue
391+
// ^ meta.directive.value.vue meta.string.vue string.quoted.double.vue punctuation.definition.string.begin.vue
392+
// ^^^^^^^^^^ meta.directive.value.vue meta.string.vue meta.embedded.expression.vue source.js.embedded.vue
393+
// ^^^ variable.other.readwrite.js
394+
// ^^ punctuation.accessor.js
395+
// ^^^^ meta.property.object.js
396+
// ^ keyword.operator.logical.js
397+
// ^ meta.directive.value.vue meta.string.vue string.quoted.double.vue punctuation.definition.string.end.vue
398+
// ^^ punctuation.definition.tag.end.html

0 commit comments

Comments
 (0)