Skip to content

Commit

Permalink
Merge pull request sublimehq#1007 from Thom1729/javascipt-prototype-c…
Browse files Browse the repository at this point in the history
…omments

[JavaScript] Use prototype for comments
  • Loading branch information
wbond authored Jun 8, 2017
2 parents 4ecf4bc + 58d34db commit e91aa36
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 25 deletions.
40 changes: 16 additions & 24 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ contexts:
- include: keywords-top-level
- include: statements

prototype:
- include: comments

keywords-top-level:
- match: \bimport\b
scope: meta.import.js keyword.control.import-export.js
Expand All @@ -40,7 +43,6 @@ contexts:
import-extended:
- meta_content_scope: meta.import.js
- include: import-escape
- include: comments
- match: '\{'
scope: meta.block.js punctuation.section.block.js
set: import-brace
Expand All @@ -66,7 +68,6 @@ contexts:
import-extended-continue:
- meta_scope: meta.import.js
- include: import-escape
- include: comments
- match: ','
scope: punctuation.separator.comma.js
set: import-extended
Expand All @@ -76,7 +77,6 @@ contexts:
import-brace:
- meta_content_scope: meta.import.js meta.block.js
- include: import-escape
- include: comments
- match: '\}'
scope: punctuation.section.block.js
set: import-extended-as
Expand All @@ -102,7 +102,6 @@ contexts:
import-brace-continue:
- meta_scope: meta.import.js meta.block.js
- include: import-escape
- include: comments
- match: '(?=\})'
set: import-brace
- match: ','
Expand All @@ -113,7 +112,6 @@ contexts:

import-final:
- meta_scope: meta.import.js
- include: comments
- match: '\bfrom\b'
scope: keyword.control.import-export.js
- include: literal-string
Expand All @@ -135,7 +133,6 @@ contexts:
pop: true
- include: expressions
- include: export-escape
- include: comments
- match: '\bdefault\b'
scope: keyword.control.import-export.js
set:
Expand Down Expand Up @@ -165,7 +162,6 @@ contexts:
export-extended-continue:
- meta_scope: meta.export.js
- include: export-escape
- include: comments
- match: ','
scope: punctuation.separator.comma.js
set: export-extended
Expand All @@ -175,7 +171,6 @@ contexts:
export-brace:
- meta_content_scope: meta.export.js meta.block.js
- include: export-escape
- include: comments
- match: '\}'
scope: punctuation.section.block.js
set: export-extended-as
Expand Down Expand Up @@ -205,7 +200,6 @@ contexts:
export-brace-continue:
- meta_scope: meta.export.js meta.block.js
- include: export-escape
- include: comments
- match: '(?=\})'
set: export-brace
- match: ','
Expand All @@ -216,7 +210,6 @@ contexts:

export-final:
- meta_scope: meta.export.js
- include: comments
- match: '\bfrom\b'
scope: keyword.control.import-export.js
- include: literal-string
Expand Down Expand Up @@ -270,7 +263,6 @@ contexts:
scope: keyword.control.loop.js
push:
- meta_scope: meta.do-while.js
- include: comments
- match: '\{'
scope: punctuation.section.block.js
push:
Expand Down Expand Up @@ -352,7 +344,6 @@ contexts:
- include: block-scope

block-scope:
- include: comments
- match: '\}'
scope: meta.block.js punctuation.section.block.js
pop: true
Expand All @@ -367,7 +358,6 @@ contexts:
pop: true

expressions:
- include: comments
- include: regexp-complete
- include: literal-string
- include: literal-string-template
Expand Down Expand Up @@ -424,20 +414,23 @@ contexts:
- match: /\*\*(?!/)
scope: punctuation.definition.comment.js
push:
- meta_include_prototype: false
- meta_scope: comment.block.documentation.js
- match: \*/
scope: punctuation.definition.comment.js
pop: true
- match: /\*
scope: punctuation.definition.comment.js
push:
- meta_include_prototype: false
- meta_scope: comment.block.js
- match: \*/
scope: punctuation.definition.comment.js
pop: true
- match: //
scope: punctuation.definition.comment.js
push:
- meta_include_prototype: false
- meta_scope: comment.line.double-slash.js
- match: \n
pop: true
Expand All @@ -446,6 +439,7 @@ contexts:
- match: "'"
scope: punctuation.definition.string.begin.js
push:
- meta_include_prototype: false
- meta_scope: string.quoted.single.js
- match: (')|(\n)
captures:
Expand All @@ -457,6 +451,7 @@ contexts:
captures:
0: punctuation.definition.string.begin.js
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.js
- match: (")|(\n)
captures:
Expand All @@ -471,6 +466,7 @@ contexts:
1: variable.function.tagged-template.js
2: punctuation.definition.string.template.begin.js
push:
- meta_include_prototype: false
- meta_scope: string.template.js
- match: "`"
scope: punctuation.definition.string.template.end.js
Expand Down Expand Up @@ -500,6 +496,7 @@ contexts:
push: regexp

regexp:
- meta_include_prototype: false
- meta_scope: string.regexp.js
- match: "(/)([gimyu]*)"
captures:
Expand All @@ -508,6 +505,7 @@ contexts:
set: after-identifier
- match: '(?=.|\n)'
push:
- meta_include_prototype: false
- match: '(?=/)'
pop: true
- include: scope:source.regexp.js
Expand Down Expand Up @@ -677,11 +675,9 @@ contexts:
pop: true
- match: '{{identifier}}'
scope: entity.name.class.js
- include: comments

class-body:
- meta_scope: meta.class.js meta.block.js
- include: comments
- match: '\}'
scope: punctuation.section.block.js
pop: true
Expand Down Expand Up @@ -856,7 +852,6 @@ contexts:
push: arrow-function-declaration

function-declaration:
- include: comments
- match: '\b(async)\b\s*'
scope: meta.function.declaration.js
captures:
Expand Down Expand Up @@ -898,7 +893,6 @@ contexts:

arrow-function-declaration-continuation:
- meta_content_scope: meta.function.declaration.js
- include: comments
- match: '(?=\{)'
set: function-block
- match: '(?=\S)'
Expand Down Expand Up @@ -982,7 +976,6 @@ contexts:
- match: "(?=[,)])"
pop: true
- include: expressions
- include: comments

label:
- match: '^\s*((?!default){{identifier}})\s*(:)'
Expand All @@ -998,7 +991,6 @@ contexts:
- match: '\}'
scope: punctuation.section.block.js
set: after-identifier
- include: comments
- match: \[
scope: punctuation.section.brackets.js
push:
Expand Down Expand Up @@ -1036,6 +1028,7 @@ contexts:
- match: "'"
scope: punctuation.definition.string.begin.js
push:
- meta_include_prototype: false
- meta_scope: string.quoted.single.js
- meta_content_scope: entity.name.function.js
- match: (')|(\n)
Expand All @@ -1047,6 +1040,7 @@ contexts:
- match: '"'
scope: punctuation.definition.string.begin.js
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.js
- meta_content_scope: entity.name.function.js
- match: (")|(\n)
Expand Down Expand Up @@ -1091,7 +1085,6 @@ contexts:
- match: "(?=\\}|,|('[^']*'|\"[^\"]*\"|{{identifier}})\\s*:)"
pop: true
- include: expressions
- include: comments

method-declaration:
- match: \b(get|set)\b(?!\s*\()\s*
Expand Down Expand Up @@ -1122,7 +1115,6 @@ contexts:
scope: punctuation.section.block.js
pop: true
- include: statements
- include: comments
- match: '(?=\S)'
pop: true
- match: (?=('[^\\]*'|"[^\\]*")\s*\()
Expand All @@ -1131,6 +1123,7 @@ contexts:
- match: "'"
scope: punctuation.definition.string.begin.js
push:
- meta_include_prototype: false
- meta_scope: string.quoted.single.js
- meta_content_scope: entity.name.function.js
- match: (')|(\n)
Expand All @@ -1142,6 +1135,7 @@ contexts:
- match: '"'
scope: punctuation.definition.string.begin.js
push:
- meta_include_prototype: false
- meta_scope: string.quoted.double.js
- meta_content_scope: entity.name.function.js
- match: (")|(\n)
Expand All @@ -1160,7 +1154,6 @@ contexts:
scope: punctuation.section.block.js
pop: true
- include: statements
- include: comments
- match: '(?=\S)'
pop: true
- match: '({{identifier}})\s*(?=\()'
Expand All @@ -1177,7 +1170,6 @@ contexts:
scope: punctuation.section.block.js
pop: true
- include: statements
- include: comments
- match: '(?=\S)'
pop: true

Expand Down Expand Up @@ -1442,4 +1434,4 @@ contexts:
- match: \;
scope: punctuation.terminator.statement.js
- match: ","
scope: punctuation.separator.comma.js
scope: punctuation.separator.comma.js
42 changes: 41 additions & 1 deletion JavaScript/syntax_test_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,41 @@ x --> y;
/*@if /*/
// ^^ punctuation.definition.comment.js

// /*
not_a_comment;
// <- -comment

/* // */
not_a_comment;
// <- -comment

/* /* */
not_a_comment;
// <- -comment

'// /* not a comment';
// ^^^^^^^^^^^^^^^^^^^ -comment

"// /* not a comment";
// ^^^^^^^^^^^^^^^^^^^ -comment

`// /* not a comment`;
// ^^^^^^^^^^^^^^^^^^^ -comment

({
'// /* not a comment': x => x,
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment

"// /* not a comment": x => x,
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment

'// /* not a comment'() {},
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {}

"// /* not a comment"() {},
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -comment() {}
});

var str = '\':';
var str2 = NaN;
// <- storage.type
Expand Down Expand Up @@ -810,6 +845,11 @@ a = /\//u + 0;
// ^ keyword.operator
// ^ constant.numeric

1 /**/ / 2 / /**/ 3;
// ^ keyword.operator
// ^ constant.numeric
// ^ keyword.operator

var π = 3.141592653
// ^ variable.other.readwrite

Expand Down Expand Up @@ -1019,4 +1059,4 @@ var str = `Hello, ${name}!`;
// ^ punctuation.definition.template-expression.end

let str = navigator.userAgent.toLowerCase();
// ^^^^^^^^^ support.type.object
// ^^^^^^^^^ support.type.object

0 comments on commit e91aa36

Please sign in to comment.