From 3979a669f348e1fc084fa47d32e4b83c46eb21cc Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Wed, 8 Aug 2018 11:19:05 +0200 Subject: [PATCH] Add JavaScript coloring --- README.md | 1 + scripts/bundle.js | 1 + src/html/html.test.ts | 47 +- src/javascript/javascript.contribution.ts | 20 + src/javascript/javascript.test.ts | 553 ++++++++++++++++++++++ src/javascript/javascript.ts | 41 ++ src/less/less.test.ts | 7 +- src/monaco.contribution.ts | 1 + src/php/php.test.ts | 50 +- src/typescript/typescript.test.ts | 6 +- src/typescript/typescript.ts | 4 +- test/setup.js | 1 + 12 files changed, 711 insertions(+), 21 deletions(-) create mode 100644 src/javascript/javascript.contribution.ts create mode 100644 src/javascript/javascript.test.ts create mode 100644 src/javascript/javascript.ts diff --git a/README.md b/README.md index a46dc3ea..c11a2048 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Colorization and configuration supports for multiple languages for the Monaco Ed * html * ini * java +* javascript * lua * markdown * msdax diff --git a/scripts/bundle.js b/scripts/bundle.js index 4eb30949..8189116f 100644 --- a/scripts/bundle.js +++ b/scripts/bundle.js @@ -34,6 +34,7 @@ bundleOne('html/html'); bundleOne('ini/ini'); bundleOne('pug/pug'); bundleOne('java/java'); +bundleOne('javascript/javascript'); bundleOne('less/less'); bundleOne('lua/lua'); bundleOne('markdown/markdown'); diff --git a/src/html/html.test.ts b/src/html/html.test.ts index 07c7fe56..65c03567 100644 --- a/src/html/html.test.ts +++ b/src/html/html.test.ts @@ -7,7 +7,7 @@ import { testTokenization } from '../test/testRunner'; -testTokenization(['html', 'css'], [ +testTokenization(['html', 'css', 'javascript'], [ // Open Start Tag #1' [{ @@ -147,7 +147,13 @@ testTokenization(['html', 'css'], [ { startIndex: 12, type: 'delimiter.html' }, { startIndex: 13, type: 'attribute.value.html' }, { startIndex: 30, type: 'delimiter.html' }, - { startIndex: 31, type: '' }, + { startIndex: 31, type: 'keyword.js' }, + { startIndex: 34, type: '' }, + { startIndex: 35, type: 'identifier.js' }, + { startIndex: 36, type: 'delimiter.js' }, + { startIndex: 37, type: '' }, + { startIndex: 38, type: 'number.js' }, + { startIndex: 40, type: 'delimiter.js' }, { startIndex: 41, type: 'delimiter.html' }, { startIndex: 43, type: 'tag.html' }, { startIndex: 49, type: 'delimiter.html' } @@ -169,7 +175,13 @@ testTokenization(['html', 'css'], [ }, { line: 'var i= 10;', tokens: [ - { startIndex: 0, type: '' }, + { startIndex: 0, type: 'keyword.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: 'delimiter.js' }, + { startIndex: 6, type: '' }, + { startIndex: 7, type: 'number.js' }, + { startIndex: 9, type: 'delimiter.js' }, ] }, { line: '', @@ -191,7 +203,14 @@ testTokenization(['html', 'css'], [ { startIndex: 12, type: 'delimiter.html' }, { startIndex: 13, type: 'attribute.value.html' }, { startIndex: 30, type: 'delimiter.html' }, - { startIndex: 31, type: '' }, + { startIndex: 31, type: 'keyword.js' }, + { startIndex: 34, type: '' }, + { startIndex: 35, type: 'identifier.js' }, + { startIndex: 36, type: 'delimiter.js' }, + { startIndex: 37, type: '' }, + { startIndex: 38, type: 'number.js' }, + { startIndex: 40, type: 'delimiter.js' }, + ] }, { line: '', @@ -217,7 +236,13 @@ testTokenization(['html', 'css'], [ }, { line: 'var i= 10;', tokens: [ - { startIndex: 0, type: '' }, + { startIndex: 0, type: 'keyword.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: 'delimiter.js' }, + { startIndex: 6, type: '' }, + { startIndex: 7, type: 'number.js' }, + { startIndex: 9, type: 'delimiter.js' }, { startIndex: 10, type: 'delimiter.html' }, { startIndex: 12, type: 'tag.html' }, { startIndex: 18, type: 'delimiter.html' } @@ -254,14 +279,14 @@ testTokenization(['html', 'css'], [ { startIndex: 0, type: 'delimiter.html' }, { startIndex: 1, type: 'tag.html' }, { startIndex: 7, type: 'delimiter.html' }, - { startIndex: 8, type: '' }, + { startIndex: 8, type: 'identifier.js' }, { startIndex: 9, type: 'delimiter.html' }, { startIndex: 11, type: 'tag.html' }, { startIndex: 17, type: 'delimiter.html' }, // { startIndex:18, type: 'delimiter.html' }, { startIndex: 19, type: 'tag.html' }, { startIndex: 25, type: 'delimiter.html' }, - { startIndex: 26, type: '' }, + { startIndex: 26, type: 'identifier.js' }, { startIndex: 27, type: 'delimiter.html' }, { startIndex: 29, type: 'tag.html' }, { startIndex: 35, type: 'delimiter.html' } @@ -292,7 +317,13 @@ testTokenization(['html', 'css'], [ { startIndex: 0, type: 'delimiter.html' }, { startIndex: 1, type: 'tag.html' }, { startIndex: 7, type: 'delimiter.html' }, - { startIndex: 8, type: '' }, + { startIndex: 8, type: 'keyword.js' }, + { startIndex: 11, type: '' }, + { startIndex: 12, type: 'identifier.js' }, + { startIndex: 13, type: 'delimiter.js' }, + { startIndex: 14, type: '' }, + { startIndex: 15, type: 'number.js' }, + { startIndex: 17, type: 'delimiter.js' }, { startIndex: 18, type: 'delimiter.html' }, { startIndex: 20, type: 'tag.html' }, { startIndex: 26, type: 'delimiter.html' } diff --git a/src/javascript/javascript.contribution.ts b/src/javascript/javascript.contribution.ts new file mode 100644 index 00000000..32c75b71 --- /dev/null +++ b/src/javascript/javascript.contribution.ts @@ -0,0 +1,20 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ +'use strict'; + +import { registerLanguage } from '../_.contribution'; + +// Allow for running under nodejs/requirejs in tests +const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (self).monaco : monaco); + +registerLanguage({ + id: 'javascript', + extensions: ['.js', '.es6', '.jsx'], + firstLine: '^#!.*\\bnode', + filenames: ['jakefile'], + aliases: ['JavaScript', 'javascript', 'js'], + mimetypes: ['text/javascript'], + loader: () => _monaco.Promise.wrap(import('./javascript')) +}); diff --git a/src/javascript/javascript.test.ts b/src/javascript/javascript.test.ts new file mode 100644 index 00000000..e2033026 --- /dev/null +++ b/src/javascript/javascript.test.ts @@ -0,0 +1,553 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { testTokenization } from '../test/testRunner'; + +testTokenization('javascript', [ + // Keywords + [{ + line: 'var x = function() { };', + tokens: [ + { startIndex: 0, type: 'keyword.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: '' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'keyword.js' }, + { startIndex: 16, type: 'delimiter.parenthesis.js' }, + { startIndex: 18, type: '' }, + { startIndex: 19, type: 'delimiter.bracket.js' }, + { startIndex: 20, type: '' }, + { startIndex: 21, type: 'delimiter.bracket.js' }, + { startIndex: 22, type: 'delimiter.js' } + ] + }], + + [{ + line: ' var ', + tokens: [ + { startIndex: 0, type: '' }, + { startIndex: 4, type: 'keyword.js' }, + { startIndex: 7, type: '' } + ] + }], + + // Comments - single line + [{ + line: '//', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: ' // a comment', + tokens: [ + { startIndex: 0, type: '' }, + { startIndex: 4, type: 'comment.js' } + ] + }], + + [{ + line: '// a comment', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: '// a comment /*', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: '// a comment /**', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: '//sticky comment', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: 'var x = 1; // my comment // is a nice one', + tokens: [ + { startIndex: 0, type: 'keyword.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: '' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'number.js' }, + { startIndex: 9, type: 'delimiter.js' }, + { startIndex: 10, type: '' }, + { startIndex: 11, type: 'comment.js' } + ] + }], + + // Comments - range comment, single line + [{ + line: '/* a simple comment */', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: 'var x = /* a simple comment */ 1;', + tokens: [ + { startIndex: 0, type: 'keyword.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: '' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'comment.js' }, + { startIndex: 30, type: '' }, + { startIndex: 31, type: 'number.js' }, + { startIndex: 32, type: 'delimiter.js' } + ] + }], + + [{ + line: 'x = /**/;', + tokens: [ + { startIndex: 0, type: 'identifier.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'comment.js' }, + { startIndex: 8, type: 'delimiter.js' } + ] + }], + + [{ + line: 'x = /*/;', + tokens: [ + { startIndex: 0, type: 'identifier.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'comment.js' } + ] + }], + + // Comments - range comment, multi lines + [{ + line: '/* a multiline comment', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }, { + line: 'can actually span', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }, { + line: 'multiple lines */', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: 'var x = /* start a comment', + tokens: [ + { startIndex: 0, type: 'keyword.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: '' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'comment.js' } + ] + }, { + line: ' a ', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }, { + line: 'and end it */ var a = 2;', + tokens: [ + { startIndex: 0, type: 'comment.js' }, + { startIndex: 13, type: '' }, + { startIndex: 14, type: 'keyword.js' }, + { startIndex: 17, type: '' }, + { startIndex: 18, type: 'identifier.js' }, + { startIndex: 19, type: '' }, + { startIndex: 20, type: 'delimiter.js' }, + { startIndex: 21, type: '' }, + { startIndex: 22, type: 'number.js' }, + { startIndex: 23, type: 'delimiter.js' } + ] + }], + + // Strings + [{ + line: 'var a = \'a\';', + tokens: [ + { startIndex: 0, type: 'keyword.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: '' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'string.js' }, + { startIndex: 11, type: 'delimiter.js' } + ] + }], + + [{ + line: '"use strict";', + tokens: [ + { startIndex: 0, type: 'string.js' }, + { startIndex: 12, type: 'delimiter.js' } + ] + }], + + [{ + line: 'b = a + " \'cool\' "', + tokens: [ + { startIndex: 0, type: 'identifier.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: '' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'string.js' } + ] + }], + + [{ + line: '"escaping \\"quotes\\" is cool"', + tokens: [ + { startIndex: 0, type: 'string.js' }, + { startIndex: 10, type: 'string.escape.js' }, + { startIndex: 12, type: 'string.js' }, + { startIndex: 18, type: 'string.escape.js' }, + { startIndex: 20, type: 'string.js' }, + ] + }], + + [{ + line: '\'\'\'', + tokens: [ + { startIndex: 0, type: 'string.js' }, + { startIndex: 2, type: 'string.invalid.js' }, + ] + }], + + [{ + line: '\'\\\'\'', + tokens: [ + { startIndex: 0, type: 'string.js' }, + { startIndex: 1, type: 'string.escape.js' }, + { startIndex: 3, type: 'string.js' }, + ] + }], + + [{ + line: '\'be careful \\not to escape\'', + tokens: [ + { startIndex: 0, type: 'string.js' }, + { startIndex: 12, type: 'string.escape.js' }, + { startIndex: 14, type: 'string.js' }, + ] + }], + + // Numbers + [{ + line: '0', + tokens: [ + { startIndex: 0, type: 'number.js' } + ] + }], + + [{ + line: ' 0', + tokens: [ + { startIndex: 0, type: '' }, + { startIndex: 1, type: 'number.js' } + ] + }], + + [{ + line: ' 0 ', + tokens: [ + { startIndex: 0, type: '' }, + { startIndex: 1, type: 'number.js' }, + { startIndex: 2, type: '' } + ] + }], + + [{ + line: '0 ', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: '' } + ] + }], + + [{ + line: '0+0', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: 'delimiter.js' }, + { startIndex: 2, type: 'number.js' } + ] + }], + + [{ + line: '100+10', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 3, type: 'delimiter.js' }, + { startIndex: 4, type: 'number.js' } + ] + }], + + [{ + line: '0 + 0', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'number.js' } + ] + }], + + [{ + line: '0123', + tokens: [ + { startIndex: 0, type: 'number.octal.js' } + ] + }], + + [{ + line: '01239', + tokens: [ + { startIndex: 0, type: 'number.octal.js' }, + { startIndex: 4, type: 'number.js' } + ] + }], + + [{ + line: '0x', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: 'identifier.js' } + ] + }], + + [{ + line: '0x123', + tokens: [ + { startIndex: 0, type: 'number.hex.js' } + ] + }], + + // Regular Expressions + [{ + line: '//', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: '/**/', + tokens: [ + { startIndex: 0, type: 'comment.js' } + ] + }], + + [{ + line: '/***/', + tokens: [ + { startIndex: 0, type: 'comment.doc.js' } + ] + }], + + [{ + line: '5 / 3;', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'number.js' }, + { startIndex: 5, type: 'delimiter.js' } + ] + }], + + // Advanced regular expressions + [{ + line: '1 / 2; /* comment', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'number.js' }, + { startIndex: 5, type: 'delimiter.js' }, + { startIndex: 6, type: '' }, + { startIndex: 7, type: 'comment.js' } + ] + }], + + [{ + line: '1 / 2 / x / b;', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'number.js' }, + { startIndex: 5, type: '' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'identifier.js' }, + { startIndex: 9, type: '' }, + { startIndex: 10, type: 'delimiter.js' }, + { startIndex: 11, type: '' }, + { startIndex: 12, type: 'identifier.js' }, + { startIndex: 13, type: 'delimiter.js' } + ] + }], + + [{ + line: 'a /ads/ b;', + tokens: [ + { startIndex: 0, type: 'identifier.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: 'identifier.js' }, + { startIndex: 6, type: 'delimiter.js' }, + { startIndex: 7, type: '' }, + { startIndex: 8, type: 'identifier.js' }, + { startIndex: 9, type: 'delimiter.js' } + ] + }], + + [{ + line: '1/(2/3)/2/3;', + tokens: [ + { startIndex: 0, type: 'number.js' }, + { startIndex: 1, type: 'delimiter.js' }, + { startIndex: 2, type: 'delimiter.parenthesis.js' }, + { startIndex: 3, type: 'number.js' }, + { startIndex: 4, type: 'delimiter.js' }, + { startIndex: 5, type: 'number.js' }, + { startIndex: 6, type: 'delimiter.parenthesis.js' }, + { startIndex: 7, type: 'delimiter.js' }, + { startIndex: 8, type: 'number.js' }, + { startIndex: 9, type: 'delimiter.js' }, + { startIndex: 10, type: 'number.js' }, + { startIndex: 11, type: 'delimiter.js' } + ] + }], + + [{ + line: '{ key: 123 }', + tokens: [ + { startIndex: 0, type: 'delimiter.bracket.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'identifier.js' }, + { startIndex: 5, type: 'delimiter.js' }, + { startIndex: 6, type: '' }, + { startIndex: 7, type: 'number.js' }, + { startIndex: 10, type: '' }, + { startIndex: 11, type: 'delimiter.bracket.js' } + ] + }], + + [{ + line: '[1,2,3]', + tokens: [ + { startIndex: 0, type: 'delimiter.square.js' }, + { startIndex: 1, type: 'number.js' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: 'number.js' }, + { startIndex: 4, type: 'delimiter.js' }, + { startIndex: 5, type: 'number.js' }, + { startIndex: 6, type: 'delimiter.square.js' } + ] + }], + + [{ + line: 'foo(123);', + tokens: [ + { startIndex: 0, type: 'identifier.js' }, + { startIndex: 3, type: 'delimiter.parenthesis.js' }, + { startIndex: 4, type: 'number.js' }, + { startIndex: 7, type: 'delimiter.parenthesis.js' }, + { startIndex: 8, type: 'delimiter.js' } + ] + }], + + [{ + line: '{a:{b:[]}}', + tokens: [ + { startIndex: 0, type: 'delimiter.bracket.js' }, + { startIndex: 1, type: 'identifier.js' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: 'delimiter.bracket.js' }, + { startIndex: 4, type: 'identifier.js' }, + { startIndex: 5, type: 'delimiter.js' }, + { startIndex: 6, type: 'delimiter.square.js' }, + { startIndex: 8, type: 'delimiter.bracket.js' } + ] + }], + + [{ + line: 'x = "[{()}]"', + tokens: [ + { startIndex: 0, type: 'identifier.js' }, + { startIndex: 1, type: '' }, + { startIndex: 2, type: 'delimiter.js' }, + { startIndex: 3, type: '' }, + { startIndex: 4, type: 'string.js' } + ] + }], + + + [{ + line: '`${5 + \'x\' + 3}a${4}`', + tokens: [ + { startIndex: 0, type: 'string.js' }, + { startIndex: 1, type: 'delimiter.bracket.js' }, + { startIndex: 3, type: 'number.js' }, + { startIndex: 4, type: '' }, + { startIndex: 5, type: 'delimiter.js' }, + { startIndex: 6, type: '' }, + { startIndex: 7, type: 'string.js' }, + { startIndex: 10, type: '' }, + { startIndex: 11, type: 'delimiter.js' }, + { startIndex: 12, type: '' }, + { startIndex: 13, type: 'number.js' }, + { startIndex: 14, type: 'delimiter.bracket.js' }, + { startIndex: 15, type: 'string.js' }, + { startIndex: 16, type: 'delimiter.bracket.js' }, + { startIndex: 18, type: 'number.js' }, + { startIndex: 19, type: 'delimiter.bracket.js' }, + { startIndex: 20, type: 'string.js' }, + + ] + }] + +]); diff --git a/src/javascript/javascript.ts b/src/javascript/javascript.ts new file mode 100644 index 00000000..9b57ca9d --- /dev/null +++ b/src/javascript/javascript.ts @@ -0,0 +1,41 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { conf as tsConf, language as tsLanguage } from '../typescript/typescript'; +import IRichLanguageConfiguration = monaco.languages.LanguageConfiguration; +import ILanguage = monaco.languages.IMonarchLanguage; + +// Allow for running under nodejs/requirejs in tests +const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (self).monaco : monaco); + +export const conf: IRichLanguageConfiguration = tsConf; + +export const language = { + // Set defaultToken to invalid to see what you do not tokenize yet + defaultToken: 'invalid', + tokenPostfix: '.js', + + keywords: [ + 'break', 'case', 'catch', 'class', 'continue', 'const', + 'constructor', 'debugger', 'default', 'delete', 'do', 'else', + 'export', 'extends', 'false', 'finally', 'for', 'from', 'function', + 'get', 'if', 'import', 'in', 'instanceof', 'let', 'new', 'null', + 'return', 'set', 'super', 'switch', 'symbol', 'this', 'throw', 'true', + 'try', 'typeof', 'undefined', 'var', 'void', 'while', 'with', 'yield', + 'async', 'await', 'of' + ], + typeKeywords: [], + + operators: tsLanguage.operators, + symbols: tsLanguage.symbols, + escapes: tsLanguage.escapes, + digits: tsLanguage.digits, + octaldigits: tsLanguage.octaldigits, + binarydigits: tsLanguage.binarydigits, + hexdigits: tsLanguage.hexdigits, + tokenizer: tsLanguage.tokenizer, +}; diff --git a/src/less/less.test.ts b/src/less/less.test.ts index 3b9eff59..c3b3fd5e 100644 --- a/src/less/less.test.ts +++ b/src/less/less.test.ts @@ -7,7 +7,7 @@ import { testTokenization } from '../test/testRunner'; -testTokenization(['less'], [ +testTokenization(['less', 'javascript'], [ // Keywords [{ @@ -641,7 +641,10 @@ testTokenization(['less'], [ { startIndex: 5, type: 'delimiter.less' }, { startIndex: 6, type: '' }, { startIndex: 7, type: 'delimiter.backtick.less' }, - { startIndex: 8, type: '' }, + { startIndex: 8, type: 'keyword.js' }, + { startIndex: 16, type: '' }, + { startIndex: 17, type: 'identifier.js' }, + { startIndex: 24, type: 'delimiter.parenthesis.js' }, { startIndex: 26, type: 'delimiter.backtick.less' }, { startIndex: 27, type: '' }, { startIndex: 28, type: 'comment.less' } diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index 9148aa98..1baa3237 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -17,6 +17,7 @@ import './handlebars/handlebars.contribution'; import './html/html.contribution'; import './ini/ini.contribution'; import './java/java.contribution'; +import './javascript/javascript.contribution'; import './less/less.contribution'; import './lua/lua.contribution'; import './markdown/markdown.contribution'; diff --git a/src/php/php.test.ts b/src/php/php.test.ts index 1e3c29db..38f6cdd1 100644 --- a/src/php/php.test.ts +++ b/src/php/php.test.ts @@ -7,7 +7,7 @@ import { testTokenization } from '../test/testRunner'; -testTokenization(['php', 'css'], [ +testTokenization(['php', 'css', 'javascript'], [ // Bug 13596:[ErrorTelemetry] Stream did not advance while tokenizing. Mode id is php (stuck) // We're testing the fact that tokenize does not throw [ @@ -1863,7 +1863,13 @@ testTokenization(['php', 'css'], [ // { startIndex:5, type: 'delimiter.html' }, { startIndex: 6, type: 'tag.html' }, { startIndex: 12, type: 'delimiter.html' }, - { startIndex: 13, type: '' }, + { startIndex: 13, type: 'keyword.js' }, + { startIndex: 16, type: '' }, + { startIndex: 17, type: 'identifier.js' }, + { startIndex: 18, type: 'delimiter.js' }, + { startIndex: 19, type: '' }, + { startIndex: 20, type: 'number.js' }, + { startIndex: 22, type: 'delimiter.js' }, { startIndex: 23, type: 'delimiter.html' }, { startIndex: 25, type: 'tag.html' }, { startIndex: 31, type: 'delimiter.html' }, @@ -1888,7 +1894,13 @@ testTokenization(['php', 'css'], [ // { startIndex:5, type: 'delimiter.html' }, { startIndex: 6, type: 'tag.html' }, { startIndex: 12, type: 'delimiter.html' }, - { startIndex: 13, type: '' }, + { startIndex: 13, type: 'keyword.js' }, + { startIndex: 16, type: '' }, + { startIndex: 17, type: 'identifier.js' }, + { startIndex: 18, type: 'delimiter.js' }, + { startIndex: 19, type: '' }, + { startIndex: 20, type: 'number.js' }, + { startIndex: 22, type: 'delimiter.js' }, { startIndex: 23, type: 'delimiter.html' }, { startIndex: 25, type: 'tag.html' }, { startIndex: 31, type: 'delimiter.html' }, @@ -1900,7 +1912,13 @@ testTokenization(['php', 'css'], [ { startIndex: 42, type: 'delimiter.html' }, { startIndex: 43, type: 'tag.html' }, { startIndex: 49, type: 'delimiter.html' }, - { startIndex: 50, type: '' }, + { startIndex: 50, type: 'keyword.js' }, + { startIndex: 53, type: '' }, + { startIndex: 54, type: 'identifier.js' }, + { startIndex: 55, type: 'delimiter.js' }, + { startIndex: 56, type: '' }, + { startIndex: 57, type: 'number.js' }, + { startIndex: 59, type: 'delimiter.js' }, { startIndex: 60, type: 'delimiter.html' }, { startIndex: 62, type: 'tag.html' }, { startIndex: 68, type: 'delimiter.html' } @@ -1969,12 +1987,28 @@ testTokenization(['php', 'css'], [ { startIndex: 73, type: 'delimiter.html' }, { startIndex: 74, type: 'tag.html' }, { startIndex: 80, type: 'delimiter.html' }, - { startIndex: 81, type: '' }, + { startIndex: 81, type: 'keyword.js' }, + { startIndex: 84, type: '' }, + { startIndex: 85, type: 'identifier.js' }, + { startIndex: 86, type: '' }, + { startIndex: 87, type: 'delimiter.js' }, + { startIndex: 88, type: '' }, + { startIndex: 89, type: 'number.js' }, + { startIndex: 90, type: 'delimiter.js' }, + { startIndex: 91, type: 'comment.js' }, { startIndex: 94, type: 'metatag.php' }, { startIndex: 97, type: 'string.php' }, { startIndex: 109, type: 'comment.php' }, { startIndex: 122, type: 'metatag.php' }, { startIndex: 124, type: '' }, + { startIndex: 127, type: 'keyword.js' }, + { startIndex: 130, type: '' }, + { startIndex: 131, type: 'identifier.js' }, + { startIndex: 132, type: '' }, + { startIndex: 133, type: 'delimiter.js' }, + { startIndex: 134, type: '' }, + { startIndex: 135, type: 'number.js' }, + { startIndex: 136, type: 'delimiter.js' }, { startIndex: 137, type: 'delimiter.html' }, { startIndex: 139, type: 'tag.html' }, { startIndex: 145, type: 'delimiter.html' }, @@ -2010,7 +2044,7 @@ testTokenization(['php', 'css'], [ { startIndex: 0, type: 'delimiter.html' }, { startIndex: 1, type: 'tag.html' }, { startIndex: 7, type: 'delimiter.html' }, - { startIndex: 8, type: '' }, + { startIndex: 8, type: 'comment.js' }, { startIndex: 10, type: 'metatag.php' } ] }], @@ -2021,13 +2055,13 @@ testTokenization(['php', 'css'], [ { startIndex: 0, type: 'delimiter.html' }, { startIndex: 1, type: 'tag.html' }, { startIndex: 7, type: 'delimiter.html' }, - { startIndex: 8, type: '' }, + { startIndex: 8, type: 'string.invalid.js' }, { startIndex: 9, type: 'metatag.php' }, { startIndex: 14, type: 'number.php' }, { startIndex: 15, type: 'delimiter.php' }, { startIndex: 16, type: 'number.php' }, { startIndex: 17, type: 'metatag.php' }, - { startIndex: 19, type: '' } + { startIndex: 19, type: 'string.invalid.js' } ] }], diff --git a/src/typescript/typescript.test.ts b/src/typescript/typescript.test.ts index b783377c..221a64f2 100644 --- a/src/typescript/typescript.test.ts +++ b/src/typescript/typescript.test.ts @@ -527,7 +527,7 @@ testTokenization('typescript', [ [{ - line: '`${5 + \'x\' + ()3}`', + line: '`${5 + \'x\' + ()3}a${4}`', tokens: [ { startIndex: 0, type: 'string.ts' }, { startIndex: 1, type: 'delimiter.bracket.ts' }, @@ -547,6 +547,10 @@ testTokenization('typescript', [ { startIndex: 20, type: 'number.ts' }, { startIndex: 21, type: 'delimiter.bracket.ts' }, { startIndex: 22, type: 'string.ts' }, + { startIndex: 23, type: 'delimiter.bracket.ts' }, + { startIndex: 25, type: 'number.ts' }, + { startIndex: 26, type: 'delimiter.bracket.ts' }, + { startIndex: 27, type: 'string.ts' }, ] }] diff --git a/src/typescript/typescript.ts b/src/typescript/typescript.ts index 81a6c334..cba42190 100644 --- a/src/typescript/typescript.ts +++ b/src/typescript/typescript.ts @@ -67,7 +67,7 @@ export const conf: IRichLanguageConfiguration = { } }; -export const language = { +export const language = { // Set defaultToken to invalid to see what you do not tokenize yet defaultToken: 'invalid', tokenPostfix: '.ts', @@ -190,7 +190,7 @@ export const language = { string_backtick: [ [/\$\{/, { token: 'delimiter.bracket', next: '@bracketCounting' }], - [/[^\\`]+/, 'string'], + [/[^\\`$]+/, 'string'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/`/, 'string', '@pop'] diff --git a/test/setup.js b/test/setup.js index 1583d9b5..ba04fcf6 100644 --- a/test/setup.js +++ b/test/setup.js @@ -38,6 +38,7 @@ define(['require'], function (require) { 'release/dev/html/html.test', 'release/dev/pug/pug.test', 'release/dev/java/java.test', + 'release/dev/javascript/javascript.test', 'release/dev/less/less.test', 'release/dev/lua/lua.test', 'release/dev/markdown/markdown.test',