Add support scope to new.target and import.meta

Fixes #609
This commit is contained in:
Sheetal Nandi 2018-04-30 12:52:46 -07:00
Родитель 2b74d88c64
Коммит 90f6ae16b3
5 изменённых файлов: 310 добавлений и 0 удалений

Просмотреть файл

@ -1521,6 +1521,20 @@ repository:
'2': { name: punctuation.accessor.ts }
'3': { name: punctuation.accessor.optional.ts }
'4': { name: support.function.json.ts }
# import meta
- match: '{{startOfIdentifier}}(import)\s*{{propertyAccess}}\s*(meta)\b(?!\$)'
captures:
'1': { name: keyword.control.import.ts }
'2': { name: punctuation.accessor.ts }
'3': { name: punctuation.accessor.optional.ts }
'4': { name: support.variable.property.importmeta.ts }
# new target
- match: '{{startOfIdentifier}}(new)\s*{{propertyAccess}}\s*(target)\b(?!\$)'
captures:
'1': { name: keyword.operator.new.ts }
'2': { name: punctuation.accessor.ts }
'3': { name: punctuation.accessor.optional.ts }
'4': { name: support.variable.property.target.ts }
# DOM
- match: |-
(?x) {{propertyAccess}} \s* (?:

Просмотреть файл

@ -4737,6 +4737,60 @@
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(import)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(meta)\b(?!\$)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.import.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.accessor.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.accessor.optional.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>support.variable.property.importmeta.ts</string>
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(target)\b(?!\$)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.new.ts</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.accessor.ts</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.accessor.optional.ts</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>support.variable.property.target.ts</string>
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?x) (?:(\.)|(\?\.(?!\s*[[:digit:]]))) \s* (?:

Просмотреть файл

@ -4683,6 +4683,60 @@
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(import)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(meta)\b(?!\$)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.import.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.accessor.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.accessor.optional.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>support.variable.property.importmeta.tsx</string>
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?&lt;![_$[:alnum:]])(?:(?&lt;=\.\.\.)|(?&lt;!\.))(new)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(target)\b(?!\$)</string>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.new.tsx</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>punctuation.accessor.tsx</string>
</dict>
<key>3</key>
<dict>
<key>name</key>
<string>punctuation.accessor.optional.tsx</string>
</dict>
<key>4</key>
<dict>
<key>name</key>
<string>support.variable.property.target.tsx</string>
</dict>
</dict>
</dict>
<dict>
<key>match</key>
<string>(?x) (?:(\.)|(\?\.(?!\s*[[:digit:]]))) \s* (?:

Просмотреть файл

@ -0,0 +1,178 @@
original file
-----------------------------------
const size = import.meta.scriptElement.dataset.size || 300;
export function Date(...args) {
if (new.target) {
// [[Construct]] branch
initializeDate(this, ...args);
} else {
// [[Call]] branch
return ToDateString(clockGetTime());
}
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>const size = import.meta.scriptElement.dataset.size || 300;
^^^^^
source.ts meta.var.expr.ts storage.type.ts
^
source.ts meta.var.expr.ts
^^^^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
^
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
^
source.ts meta.var.expr.ts keyword.operator.assignment.ts
^
source.ts meta.var.expr.ts
^^^^^^
source.ts meta.var.expr.ts keyword.control.import.ts
^
source.ts meta.var.expr.ts punctuation.accessor.ts
^^^^
source.ts meta.var.expr.ts support.variable.property.importmeta.ts
^
source.ts meta.var.expr.ts punctuation.accessor.ts
^^^^^^^^^^^^^
source.ts meta.var.expr.ts variable.other.object.property.ts
^
source.ts meta.var.expr.ts punctuation.accessor.ts
^^^^^^^
source.ts meta.var.expr.ts variable.other.object.property.ts
^
source.ts meta.var.expr.ts punctuation.accessor.ts
^^^^
source.ts meta.var.expr.ts support.variable.property.dom.ts
^
source.ts meta.var.expr.ts
^^
source.ts meta.var.expr.ts keyword.operator.logical.ts
^
source.ts meta.var.expr.ts
^^^
source.ts meta.var.expr.ts constant.numeric.decimal.ts
^
source.ts punctuation.terminator.statement.ts
>export function Date(...args) {
^^^^^^
source.ts meta.function.ts keyword.control.export.ts
^
source.ts meta.function.ts
^^^^^^^^
source.ts meta.function.ts storage.type.function.ts
^
source.ts meta.function.ts
^^^^
source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts
^
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^
source.ts meta.function.ts meta.parameters.ts keyword.operator.rest.ts
^^^^
source.ts meta.function.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.function.ts
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
> if (new.target) {
^^
source.ts meta.function.ts meta.block.ts
^^
source.ts meta.function.ts meta.block.ts keyword.control.conditional.ts
^
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.brace.round.ts
^^^
source.ts meta.function.ts meta.block.ts keyword.operator.new.ts
^
source.ts meta.function.ts meta.block.ts punctuation.accessor.ts
^^^^^^
source.ts meta.function.ts meta.block.ts support.variable.property.target.ts
^
source.ts meta.function.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.definition.block.ts
> // [[Construct]] branch
^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.whitespace.comment.leading.ts
^^
source.ts meta.function.ts meta.block.ts meta.block.ts comment.line.double-slash.ts punctuation.definition.comment.ts
^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts comment.line.double-slash.ts
> initializeDate(this, ...args);
^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts
^^^^^^^^^^^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.brace.round.ts
^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts variable.language.this.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.separator.comma.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts
^^^
source.ts meta.function.ts meta.block.ts meta.block.ts keyword.operator.spread.ts
^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts variable.other.readwrite.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.terminator.statement.ts
> } else {
^^
source.ts meta.function.ts meta.block.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.definition.block.ts
^
source.ts meta.function.ts meta.block.ts
^^^^
source.ts meta.function.ts meta.block.ts keyword.control.conditional.ts
^
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.definition.block.ts
> // [[Call]] branch
^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.whitespace.comment.leading.ts
^^
source.ts meta.function.ts meta.block.ts meta.block.ts comment.line.double-slash.ts punctuation.definition.comment.ts
^^^^^^^^^^^^^^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts comment.line.double-slash.ts
> return ToDateString(clockGetTime());
^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts
^^^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts keyword.control.flow.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts
^^^^^^^^^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.brace.round.ts
^^^^^^^^^^^^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.function-call.ts entity.name.function.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts meta.brace.round.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.terminator.statement.ts
> }
^^
source.ts meta.function.ts meta.block.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts meta.block.ts punctuation.definition.block.ts
>}
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts

10
tests/cases/Issue609.ts Normal file
Просмотреть файл

@ -0,0 +1,10 @@
const size = import.meta.scriptElement.dataset.size || 300;
export function Date(...args) {
if (new.target) {
// [[Construct]] branch
initializeDate(this, ...args);
} else {
// [[Call]] branch
return ToDateString(clockGetTime());
}
}