From fc20b196e0212137a671c24056bdbe33e73abda8 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 14:19:31 -0500 Subject: [PATCH 01/16] Added ts-node dev dependency --- package.json | 1 + yarn.lock | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/package.json b/package.json index c34119b950..72aa789129 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "prettier": "1.19.1", "rollup": "1.29.1", "rollup-plugin-commonjs": "10.1.0", + "ts-node": "^8.6.2", "tslint": "5.20.1", "tslint-eslint-rules": "5.4.0", "vsce": "1.71.0", diff --git a/yarn.lock b/yarn.lock index d8323dbd7c..3a412c3da8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -67,6 +67,11 @@ ansi-styles@^3.2.1: dependencies: color-convert "^1.9.0" +arg@^4.1.0: + version "4.1.2" + resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.2.tgz#e70c90579e02c63d80e3ad4e31d8bfdb8bd50064" + integrity sha512-+ytCkGcBtHZ3V2r2Z06AncYO8jz46UEamcspGoU8lHcEbpn6J77QK0vdWvChsclg/tM5XIJC5tnjmPp7Eq6Obg== + argparse@^1.0.7: version "1.0.10" resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" @@ -682,6 +687,11 @@ magic-string@^0.25.2: dependencies: sourcemap-codec "^1.4.4" +make-error@^1.1.1: + version "1.3.5" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8" + integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g== + markdown-it@^8.3.1: version "8.4.2" resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54" @@ -988,6 +998,14 @@ source-map-support@^0.5.0: buffer-from "^1.0.0" source-map "^0.6.0" +source-map-support@^0.5.6: + version "0.5.16" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042" + integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ== + dependencies: + buffer-from "^1.0.0" + source-map "^0.6.0" + source-map@^0.6.0: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" @@ -1054,6 +1072,17 @@ tough-cookie@~2.4.3: psl "^1.1.24" punycode "^1.4.1" +ts-node@^8.6.2: + version "8.6.2" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.6.2.tgz#7419a01391a818fbafa6f826a33c1a13e9464e35" + integrity sha512-4mZEbofxGqLL2RImpe3zMJukvEvcO1XP8bj8ozBPySdCUXEcU5cIRwR0aM3R+VoZq7iXc8N86NC0FspGRqP4gg== + dependencies: + arg "^4.1.0" + diff "^4.0.1" + make-error "^1.1.1" + source-map-support "^0.5.6" + yn "3.1.1" + tslib@1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" @@ -1274,3 +1303,8 @@ yazl@^2.2.2: integrity sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw== dependencies: buffer-crc32 "~0.2.3" + +yn@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== From 15c8bdc36b2b5399337aa71c6e75d3a56a3bff87 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 14:22:01 -0500 Subject: [PATCH 02/16] Added tsconfig, types and build script --- syntaxes/src/build.ts | 41 +++++++++++++++++++++++++++++++++++++++++ syntaxes/src/types.ts | 19 +++++++++++++++++++ syntaxes/tsconfig.json | 7 +++++++ 3 files changed, 67 insertions(+) create mode 100644 syntaxes/src/build.ts create mode 100644 syntaxes/src/types.ts create mode 100644 syntaxes/tsconfig.json diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts new file mode 100644 index 0000000000..d6abad93cd --- /dev/null +++ b/syntaxes/src/build.ts @@ -0,0 +1,41 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import * as fs from 'fs'; + +import {GrammarDefinition, GrammarDefinitionValue, JsonObject, JsonObjectValue} from './types'; + +const processValue = (value: GrammarDefinitionValue): JsonObjectValue => { + if (typeof value === 'string') { + return value; + } else if (value instanceof RegExp) { + return value.toString().replace(/^\/|\/$/g, ''); + } else if (value instanceof Array) { + return value.map(processGrammar); + } + return processGrammar(value); +}; + +const processGrammar = (grammar: GrammarDefinition|GrammarDefinition[]): JsonObject => { + const processedGrammar: JsonObject = {}; + + for (const [key, value] of Object.entries(grammar)) { + processedGrammar[key] = processValue(value); + } + + return processedGrammar; +}; + +const build = (grammar: GrammarDefinition, filename: string): void => { + const processedGrammar: JsonObject = processGrammar(grammar); + const grammarContent: string = JSON.stringify(processedGrammar, null, ' '); + + fs.writeFile(`syntaxes/${filename}.json`, grammarContent, (error) => { + if (error) throw error; + }); +}; diff --git a/syntaxes/src/types.ts b/syntaxes/src/types.ts new file mode 100644 index 0000000000..a680a076df --- /dev/null +++ b/syntaxes/src/types.ts @@ -0,0 +1,19 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +export type GrammarDefinitionValue = string|RegExp|GrammarDefinition|GrammarDefinition[]; + +export interface GrammarDefinition { + [key: string]: GrammarDefinitionValue; +} + +export type JsonObjectValue = string|JsonObject|JsonObject[]; + +export interface JsonObject { + [key: string]: JsonObjectValue; +} diff --git a/syntaxes/tsconfig.json b/syntaxes/tsconfig.json new file mode 100644 index 0000000000..046fa6b876 --- /dev/null +++ b/syntaxes/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "out" + }, + "include": ["src"] +} From a2d26f69ece5f3c17e1e21846dd065cb3307ed84 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 14:22:19 -0500 Subject: [PATCH 03/16] Added source files for Template grammar --- syntaxes/src/template/index.ts | 36 +++++++++++++++++++ .../src/template/repository/binding-key.ts | 29 +++++++++++++++ .../src/template/repository/event-binding.ts | 32 +++++++++++++++++ .../src/template/repository/interpolation.ts | 24 +++++++++++++ .../template/repository/property-binding.ts | 32 +++++++++++++++++ .../template/repository/template-binding.ts | 32 +++++++++++++++++ .../template/repository/two-way-binding.ts | 32 +++++++++++++++++ 7 files changed, 217 insertions(+) create mode 100644 syntaxes/src/template/index.ts create mode 100644 syntaxes/src/template/repository/binding-key.ts create mode 100644 syntaxes/src/template/repository/event-binding.ts create mode 100644 syntaxes/src/template/repository/interpolation.ts create mode 100644 syntaxes/src/template/repository/property-binding.ts create mode 100644 syntaxes/src/template/repository/template-binding.ts create mode 100644 syntaxes/src/template/repository/two-way-binding.ts diff --git a/syntaxes/src/template/index.ts b/syntaxes/src/template/index.ts new file mode 100644 index 0000000000..cc73348db4 --- /dev/null +++ b/syntaxes/src/template/index.ts @@ -0,0 +1,36 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {GrammarDefinition} from '../types'; + +import {bindingKey} from './repository/binding-key'; +import {eventBinding} from './repository/event-binding'; +import {interpolation} from './repository/interpolation'; +import {propertyBinding} from './repository/property-binding'; +import {templateBinding} from './repository/template-binding'; +import {twoWayBinding} from './repository/two-way-binding'; + +export const template: GrammarDefinition = { + scopeName: 'template.ng', + injectionSelector: 'L:text.html -comment', + patterns: [ + {include: '#interpolation'}, + {include: '#propertyBinding'}, + {include: '#eventBinding'}, + {include: '#twoWayBinding'}, + {include: '#templateBinding'}, + ], + repository: { + interpolation, + propertyBinding, + eventBinding, + twoWayBinding, + templateBinding, + bindingKey, + }, +}; \ No newline at end of file diff --git a/syntaxes/src/template/repository/binding-key.ts b/syntaxes/src/template/repository/binding-key.ts new file mode 100644 index 0000000000..dc6568704d --- /dev/null +++ b/syntaxes/src/template/repository/binding-key.ts @@ -0,0 +1,29 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {GrammarDefinition} from '../../types'; + +export const bindingKey: GrammarDefinition = { + patterns: [ + { + match: /([\[\(]{1,2})(?:\s*)(@?[-_a-zA-Z0-9.$]*)(?:\s*)([\]\)]{1,2})/, + captures: { + 1: {name: 'punctuation.definition.ng-binding-name.begin.html'}, + 2: { + patterns: [ + { + match: /\./, + name: 'punctuation.accessor.html', + }, + ], + }, + 3: {name: 'punctuation.definition.ng-binding-name.end.html'}, + }, + }, + ], +}; \ No newline at end of file diff --git a/syntaxes/src/template/repository/event-binding.ts b/syntaxes/src/template/repository/event-binding.ts new file mode 100644 index 0000000000..75e040d191 --- /dev/null +++ b/syntaxes/src/template/repository/event-binding.ts @@ -0,0 +1,32 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {GrammarDefinition} from '../../types'; + +export const eventBinding: GrammarDefinition = { + begin: /(\(\s*@?[-_a-zA-Z0-9.$]*\s*\))(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.event.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.event.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], +}; \ No newline at end of file diff --git a/syntaxes/src/template/repository/interpolation.ts b/syntaxes/src/template/repository/interpolation.ts new file mode 100644 index 0000000000..b7a60325e3 --- /dev/null +++ b/syntaxes/src/template/repository/interpolation.ts @@ -0,0 +1,24 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {GrammarDefinition} from '../../types'; + +export const interpolation: GrammarDefinition = { + begin: /{{/, + beginCaptures: { + 0: {name: 'punctuation.definition.block.ts'}, + }, + end: /}}/, + endCaptures: { + 0: {name: 'punctuation.definition.block.ts'}, + }, + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], +}; \ No newline at end of file diff --git a/syntaxes/src/template/repository/property-binding.ts b/syntaxes/src/template/repository/property-binding.ts new file mode 100644 index 0000000000..237a66419e --- /dev/null +++ b/syntaxes/src/template/repository/property-binding.ts @@ -0,0 +1,32 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {GrammarDefinition} from '../../types'; + +export const propertyBinding: GrammarDefinition = { + begin: /(\[\s*@?[-_a-zA-Z0-9.$]*\s*])(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.property.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.property.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], +}; \ No newline at end of file diff --git a/syntaxes/src/template/repository/template-binding.ts b/syntaxes/src/template/repository/template-binding.ts new file mode 100644 index 0000000000..ca44928b6d --- /dev/null +++ b/syntaxes/src/template/repository/template-binding.ts @@ -0,0 +1,32 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {GrammarDefinition} from '../../types'; + +export const templateBinding: GrammarDefinition = { + begin: /(\*[-_a-zA-Z0-9.$]*)(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.template.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.template.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], +}; \ No newline at end of file diff --git a/syntaxes/src/template/repository/two-way-binding.ts b/syntaxes/src/template/repository/two-way-binding.ts new file mode 100644 index 0000000000..198d620d29 --- /dev/null +++ b/syntaxes/src/template/repository/two-way-binding.ts @@ -0,0 +1,32 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {GrammarDefinition} from '../../types'; + +export const twoWayBinding: GrammarDefinition = { + begin: /(\[\s*\(\s*@?[-_a-zA-Z0-9.$]*\s*\)\s*\])(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.two-way.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.two-way.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], +}; \ No newline at end of file From 6e1ca711939c9b77e753b60017e1fded5d539a4a Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 14:23:48 -0500 Subject: [PATCH 04/16] npm script for building grammars --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 72aa789129..5c743f85c5 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "compile:test": "tsc -b server/src/tests", "compile:integration": "tsc -b integration", "compile:syntaxes-test": "tsc -b syntaxes/test", + "build:syntaxes": "ts-node syntaxes/src/build.ts", "format": "scripts/format.sh", "watch": "tsc -b -w", "postinstall": "vscode-install && cd client && yarn && cd ../server && yarn && cd ..", From d334fbb9322a9f3daf7768765d8012629bc65aff Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 14:24:11 -0500 Subject: [PATCH 05/16] Built template.json from source --- syntaxes/src/build.ts | 4 ++++ syntaxes/template.json | 7 +------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index d6abad93cd..02842447c6 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -10,6 +10,8 @@ import * as fs from 'fs'; import {GrammarDefinition, GrammarDefinitionValue, JsonObject, JsonObjectValue} from './types'; +import {template} from './template'; + const processValue = (value: GrammarDefinitionValue): JsonObjectValue => { if (typeof value === 'string') { return value; @@ -39,3 +41,5 @@ const build = (grammar: GrammarDefinition, filename: string): void => { if (error) throw error; }); }; + +build(template, 'template'); diff --git a/syntaxes/template.json b/syntaxes/template.json index e0a84e8f9b..9edfb88053 100644 --- a/syntaxes/template.json +++ b/syntaxes/template.json @@ -39,7 +39,6 @@ } ] }, - "propertyBinding": { "begin": "(\\[\\s*@?[-_a-zA-Z0-9.$]*\\s*])(=)([\"'])", "beginCaptures": { @@ -72,7 +71,6 @@ } ] }, - "eventBinding": { "begin": "(\\(\\s*@?[-_a-zA-Z0-9.$]*\\s*\\))(=)([\"'])", "beginCaptures": { @@ -105,7 +103,6 @@ } ] }, - "twoWayBinding": { "begin": "(\\[\\s*\\(\\s*@?[-_a-zA-Z0-9.$]*\\s*\\)\\s*\\])(=)([\"'])", "beginCaptures": { @@ -138,7 +135,6 @@ } ] }, - "templateBinding": { "begin": "(\\*[-_a-zA-Z0-9.$]*)(=)([\"'])", "beginCaptures": { @@ -171,7 +167,6 @@ } ] }, - "bindingKey": { "patterns": [ { @@ -196,4 +191,4 @@ ] } } -} +} \ No newline at end of file From daebd10331c27c151f2d67868515568b49d74c08 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 15:11:54 -0500 Subject: [PATCH 06/16] Formatting --- syntaxes/src/template/index.ts | 2 +- syntaxes/src/template/repository/binding-key.ts | 2 +- syntaxes/src/template/repository/event-binding.ts | 2 +- syntaxes/src/template/repository/interpolation.ts | 2 +- syntaxes/src/template/repository/property-binding.ts | 2 +- syntaxes/src/template/repository/template-binding.ts | 2 +- syntaxes/src/template/repository/two-way-binding.ts | 2 +- syntaxes/template.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/syntaxes/src/template/index.ts b/syntaxes/src/template/index.ts index cc73348db4..d00226e20b 100644 --- a/syntaxes/src/template/index.ts +++ b/syntaxes/src/template/index.ts @@ -33,4 +33,4 @@ export const template: GrammarDefinition = { templateBinding, bindingKey, }, -}; \ No newline at end of file +}; diff --git a/syntaxes/src/template/repository/binding-key.ts b/syntaxes/src/template/repository/binding-key.ts index dc6568704d..73f44819be 100644 --- a/syntaxes/src/template/repository/binding-key.ts +++ b/syntaxes/src/template/repository/binding-key.ts @@ -26,4 +26,4 @@ export const bindingKey: GrammarDefinition = { }, }, ], -}; \ No newline at end of file +}; diff --git a/syntaxes/src/template/repository/event-binding.ts b/syntaxes/src/template/repository/event-binding.ts index 75e040d191..534c27d694 100644 --- a/syntaxes/src/template/repository/event-binding.ts +++ b/syntaxes/src/template/repository/event-binding.ts @@ -29,4 +29,4 @@ export const eventBinding: GrammarDefinition = { patterns: [ {include: 'source.js'}, ], -}; \ No newline at end of file +}; diff --git a/syntaxes/src/template/repository/interpolation.ts b/syntaxes/src/template/repository/interpolation.ts index b7a60325e3..add7964206 100644 --- a/syntaxes/src/template/repository/interpolation.ts +++ b/syntaxes/src/template/repository/interpolation.ts @@ -21,4 +21,4 @@ export const interpolation: GrammarDefinition = { patterns: [ {include: 'source.js'}, ], -}; \ No newline at end of file +}; diff --git a/syntaxes/src/template/repository/property-binding.ts b/syntaxes/src/template/repository/property-binding.ts index 237a66419e..8a29ff0f6f 100644 --- a/syntaxes/src/template/repository/property-binding.ts +++ b/syntaxes/src/template/repository/property-binding.ts @@ -29,4 +29,4 @@ export const propertyBinding: GrammarDefinition = { patterns: [ {include: 'source.js'}, ], -}; \ No newline at end of file +}; diff --git a/syntaxes/src/template/repository/template-binding.ts b/syntaxes/src/template/repository/template-binding.ts index ca44928b6d..c8595cae5a 100644 --- a/syntaxes/src/template/repository/template-binding.ts +++ b/syntaxes/src/template/repository/template-binding.ts @@ -29,4 +29,4 @@ export const templateBinding: GrammarDefinition = { patterns: [ {include: 'source.js'}, ], -}; \ No newline at end of file +}; diff --git a/syntaxes/src/template/repository/two-way-binding.ts b/syntaxes/src/template/repository/two-way-binding.ts index 198d620d29..34983d7149 100644 --- a/syntaxes/src/template/repository/two-way-binding.ts +++ b/syntaxes/src/template/repository/two-way-binding.ts @@ -29,4 +29,4 @@ export const twoWayBinding: GrammarDefinition = { patterns: [ {include: 'source.js'}, ], -}; \ No newline at end of file +}; diff --git a/syntaxes/template.json b/syntaxes/template.json index 9edfb88053..fc39500adb 100644 --- a/syntaxes/template.json +++ b/syntaxes/template.json @@ -191,4 +191,4 @@ ] } } -} \ No newline at end of file +} From b7ee67953c8aaf6bbb55880ace56368061eb70f9 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 15:16:31 -0500 Subject: [PATCH 07/16] Added final newline to build script --- syntaxes/src/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index 02842447c6..daccbfb5b7 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -35,7 +35,7 @@ const processGrammar = (grammar: GrammarDefinition|GrammarDefinition[]): JsonObj const build = (grammar: GrammarDefinition, filename: string): void => { const processedGrammar: JsonObject = processGrammar(grammar); - const grammarContent: string = JSON.stringify(processedGrammar, null, ' '); + const grammarContent: string = JSON.stringify(processedGrammar, null, ' ') + '\n'; fs.writeFile(`syntaxes/${filename}.json`, grammarContent, (error) => { if (error) throw error; From d85b3103373192ea8d8c4810d3b96c153ef02f8a Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sat, 25 Jan 2020 22:29:03 -0500 Subject: [PATCH 08/16] Fixed incorrect type --- syntaxes/src/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index daccbfb5b7..5a3b1c3f3e 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -23,7 +23,7 @@ const processValue = (value: GrammarDefinitionValue): JsonObjectValue => { return processGrammar(value); }; -const processGrammar = (grammar: GrammarDefinition|GrammarDefinition[]): JsonObject => { +const processGrammar = (grammar: GrammarDefinition): JsonObject => { const processedGrammar: JsonObject = {}; for (const [key, value] of Object.entries(grammar)) { From fa25c7d145949043dfcc2a14523983155d41f3df Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sun, 26 Jan 2020 14:50:03 -0500 Subject: [PATCH 09/16] Removed unnecessary type literal abstractions --- syntaxes/src/build.ts | 26 +++++++++++++------------- syntaxes/src/types.ts | 8 ++------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index 5a3b1c3f3e..09ad3609ac 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -8,26 +8,26 @@ import * as fs from 'fs'; -import {GrammarDefinition, GrammarDefinitionValue, JsonObject, JsonObjectValue} from './types'; +import {GrammarDefinition, JsonObject} from './types'; import {template} from './template'; -const processValue = (value: GrammarDefinitionValue): JsonObjectValue => { - if (typeof value === 'string') { - return value; - } else if (value instanceof RegExp) { - return value.toString().replace(/^\/|\/$/g, ''); - } else if (value instanceof Array) { - return value.map(processGrammar); - } - return processGrammar(value); -}; +const transformValue = (value: string|RegExp|GrammarDefinition|GrammarDefinition[]): string| + JsonObject|JsonObject[] => { + if (typeof value === 'string') { + return value; + } else if (value instanceof RegExp) { + return value.toString().replace(/^\/|\/$/g, ''); + } else if (value instanceof Array) { + return value.map(processGrammar); + } + return processGrammar(value); + }; const processGrammar = (grammar: GrammarDefinition): JsonObject => { const processedGrammar: JsonObject = {}; - for (const [key, value] of Object.entries(grammar)) { - processedGrammar[key] = processValue(value); + processedGrammar[key] = transformValue(value); } return processedGrammar; diff --git a/syntaxes/src/types.ts b/syntaxes/src/types.ts index a680a076df..6dea0ea687 100644 --- a/syntaxes/src/types.ts +++ b/syntaxes/src/types.ts @@ -6,14 +6,10 @@ * found in the LICENSE file at https://angular.io/license */ -export type GrammarDefinitionValue = string|RegExp|GrammarDefinition|GrammarDefinition[]; - export interface GrammarDefinition { - [key: string]: GrammarDefinitionValue; + [key: string]: string|RegExp|GrammarDefinition|GrammarDefinition[]; } -export type JsonObjectValue = string|JsonObject|JsonObject[]; - export interface JsonObject { - [key: string]: JsonObjectValue; + [key: string]: string|JsonObject|JsonObject[]; } From c4b5bea2fb2ca00c98ded07e1796f21cb21e3417 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sun, 26 Jan 2020 14:51:01 -0500 Subject: [PATCH 10/16] Refactored to function declarations --- syntaxes/src/build.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index 09ad3609ac..d50b29eed1 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -12,34 +12,34 @@ import {GrammarDefinition, JsonObject} from './types'; import {template} from './template'; -const transformValue = (value: string|RegExp|GrammarDefinition|GrammarDefinition[]): string| - JsonObject|JsonObject[] => { - if (typeof value === 'string') { - return value; - } else if (value instanceof RegExp) { - return value.toString().replace(/^\/|\/$/g, ''); - } else if (value instanceof Array) { - return value.map(processGrammar); - } - return processGrammar(value); - }; - -const processGrammar = (grammar: GrammarDefinition): JsonObject => { +function transformValue(value: string|RegExp|GrammarDefinition|GrammarDefinition[]): string| + JsonObject|JsonObject[] { + if (typeof value === 'string') { + return value; + } else if (value instanceof RegExp) { + return value.toString().replace(/^\/|\/$/g, ''); + } else if (value instanceof Array) { + return value.map(processGrammar); + } + return processGrammar(value); +} + +function processGrammar(grammar: GrammarDefinition): JsonObject { const processedGrammar: JsonObject = {}; for (const [key, value] of Object.entries(grammar)) { processedGrammar[key] = transformValue(value); } return processedGrammar; -}; +} -const build = (grammar: GrammarDefinition, filename: string): void => { +function build(grammar: GrammarDefinition, filename: string): void { const processedGrammar: JsonObject = processGrammar(grammar); const grammarContent: string = JSON.stringify(processedGrammar, null, ' ') + '\n'; fs.writeFile(`syntaxes/${filename}.json`, grammarContent, (error) => { if (error) throw error; }); -}; +} build(template, 'template'); From 78563d28363b7c4c324af71e1997cf0b67d4a22f Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sun, 26 Jan 2020 15:06:32 -0500 Subject: [PATCH 11/16] Refactored and added comments for clarity --- syntaxes/src/build.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index d50b29eed1..20dc10dba2 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -9,30 +9,28 @@ import * as fs from 'fs'; import {GrammarDefinition, JsonObject} from './types'; - import {template} from './template'; -function transformValue(value: string|RegExp|GrammarDefinition|GrammarDefinition[]): string| - JsonObject|JsonObject[] { - if (typeof value === 'string') { - return value; - } else if (value instanceof RegExp) { - return value.toString().replace(/^\/|\/$/g, ''); - } else if (value instanceof Array) { - return value.map(processGrammar); - } - return processGrammar(value); -} - +// Recursively transforms a TypeScript grammar definition into an object which can be processed by +// JSON.stringify to generate a valid TextMate JSON grammar definition function processGrammar(grammar: GrammarDefinition): JsonObject { const processedGrammar: JsonObject = {}; for (const [key, value] of Object.entries(grammar)) { - processedGrammar[key] = transformValue(value); + if (typeof value === 'string') { + processedGrammar[key] = value; + } else if (value instanceof RegExp) { + // Escape backslashes/quote marks and trim the demarcating `/` characters from a regex literal + processedGrammar[key] = value.toString().replace(/^\/|\/$/g, ''); + } else if (value instanceof Array) { + processedGrammar[key] = value.map(processGrammar); + } else { + processedGrammar[key] = processGrammar(value); + } } - return processedGrammar; } +// Build a TextMate grammar JSON file from a source TypeScript object function build(grammar: GrammarDefinition, filename: string): void { const processedGrammar: JsonObject = processGrammar(grammar); const grammarContent: string = JSON.stringify(processedGrammar, null, ' ') + '\n'; From a16f4acb3d86e959b4d97ad3c1cef4e34eab7340 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sun, 26 Jan 2020 15:15:02 -0500 Subject: [PATCH 12/16] Removed ts-node dev dependency --- .gitignore | 1 + package.json | 4 ++-- yarn.lock | 34 ---------------------------------- 3 files changed, 3 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 14b6473b72..f040307c4f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ dist/ .vscode/settings.json .vimrc .nvimrc +syntaxes/out syntaxes/test/*.js syntaxes/test/*.map diff --git a/package.json b/package.json index 5c743f85c5..9f561a4b39 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,8 @@ "compile:test": "tsc -b server/src/tests", "compile:integration": "tsc -b integration", "compile:syntaxes-test": "tsc -b syntaxes/test", - "build:syntaxes": "ts-node syntaxes/src/build.ts", + "compile:syntaxes": "tsc -b syntaxes", + "build:syntaxes": "yarn compile:syntaxes && node syntaxes/out/build.js", "format": "scripts/format.sh", "watch": "tsc -b -w", "postinstall": "vscode-install && cd client && yarn && cd ../server && yarn && cd ..", @@ -117,7 +118,6 @@ "prettier": "1.19.1", "rollup": "1.29.1", "rollup-plugin-commonjs": "10.1.0", - "ts-node": "^8.6.2", "tslint": "5.20.1", "tslint-eslint-rules": "5.4.0", "vsce": "1.71.0", diff --git a/yarn.lock b/yarn.lock index 3a412c3da8..d8323dbd7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -67,11 +67,6 @@ ansi-styles@^3.2.1: dependencies: color-convert "^1.9.0" -arg@^4.1.0: - version "4.1.2" - resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.2.tgz#e70c90579e02c63d80e3ad4e31d8bfdb8bd50064" - integrity sha512-+ytCkGcBtHZ3V2r2Z06AncYO8jz46UEamcspGoU8lHcEbpn6J77QK0vdWvChsclg/tM5XIJC5tnjmPp7Eq6Obg== - argparse@^1.0.7: version "1.0.10" resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" @@ -687,11 +682,6 @@ magic-string@^0.25.2: dependencies: sourcemap-codec "^1.4.4" -make-error@^1.1.1: - version "1.3.5" - resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8" - integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g== - markdown-it@^8.3.1: version "8.4.2" resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.2.tgz#386f98998dc15a37722aa7722084f4020bdd9b54" @@ -998,14 +988,6 @@ source-map-support@^0.5.0: buffer-from "^1.0.0" source-map "^0.6.0" -source-map-support@^0.5.6: - version "0.5.16" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042" - integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ== - dependencies: - buffer-from "^1.0.0" - source-map "^0.6.0" - source-map@^0.6.0: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" @@ -1072,17 +1054,6 @@ tough-cookie@~2.4.3: psl "^1.1.24" punycode "^1.4.1" -ts-node@^8.6.2: - version "8.6.2" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.6.2.tgz#7419a01391a818fbafa6f826a33c1a13e9464e35" - integrity sha512-4mZEbofxGqLL2RImpe3zMJukvEvcO1XP8bj8ozBPySdCUXEcU5cIRwR0aM3R+VoZq7iXc8N86NC0FspGRqP4gg== - dependencies: - arg "^4.1.0" - diff "^4.0.1" - make-error "^1.1.1" - source-map-support "^0.5.6" - yn "3.1.1" - tslib@1.9.0: version "1.9.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" @@ -1303,8 +1274,3 @@ yazl@^2.2.2: integrity sha512-phENi2PLiHnHb6QBVot+dJnaAZ0xosj7p3fWl+znIjBDlnMI2PsZCJZ306BPTFOaHf5qdDEI8x5qFrSOBN5vrw== dependencies: buffer-crc32 "~0.2.3" - -yn@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" - integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== From 9e3c004b6415551a74cb35f76ea876c0205e2b44 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sun, 26 Jan 2020 15:57:09 -0500 Subject: [PATCH 13/16] Bugfix: index.ts not resolved as expected when using WSL --- syntaxes/src/build.ts | 2 +- syntaxes/src/template/{index.ts => grammar.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename syntaxes/src/template/{index.ts => grammar.ts} (100%) diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index 20dc10dba2..b4d1f50e9e 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -9,7 +9,7 @@ import * as fs from 'fs'; import {GrammarDefinition, JsonObject} from './types'; -import {template} from './template'; +import {template} from './template/grammar'; // Recursively transforms a TypeScript grammar definition into an object which can be processed by // JSON.stringify to generate a valid TextMate JSON grammar definition diff --git a/syntaxes/src/template/index.ts b/syntaxes/src/template/grammar.ts similarity index 100% rename from syntaxes/src/template/index.ts rename to syntaxes/src/template/grammar.ts From ad747b9894b080dcc920fa6ce99873f357b6ab7c Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sun, 26 Jan 2020 15:59:00 -0500 Subject: [PATCH 14/16] Integrated syntax compilation into build script --- package.json | 2 +- scripts/build.sh | 7 +- scripts/cleanup.sh | 1 + syntaxes/src/build.ts | 2 +- syntaxes/template.json | 194 --------------------------------------- syntaxes/test/cases.json | 4 +- tsconfig.json | 3 +- 7 files changed, 13 insertions(+), 200 deletions(-) delete mode 100644 syntaxes/template.json diff --git a/package.json b/package.json index 9f561a4b39..6667fec630 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,7 @@ "test": "yarn compile:test && jasmine server/out/tests/*_spec.js", "test:lsp": "yarn compile:integration && jasmine integration/out/lsp/*_spec.js", "test:e2e": "yarn compile:integration && ./scripts/e2e.sh", - "test:syntaxes": "yarn compile:syntaxes-test && jasmine syntaxes/test/driver.js" + "test:syntaxes": "yarn compile:syntaxes-test && yarn build:syntaxes && jasmine syntaxes/test/driver.js" }, "dependencies": { "typescript": "~3.7.4" diff --git a/scripts/build.sh b/scripts/build.sh index 41bd943594..cfc16526a5 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -5,6 +5,7 @@ set -ex -o pipefail # Clean up from last build rm -rf client/out rm -rf server/out +rm -rf syntaxes/out rm -rf dist rm -rf **/*.tsbuildinfo @@ -17,9 +18,13 @@ cp package.json yarn.lock angular.png CHANGELOG.md README.md dist cp client/package.json client/yarn.lock dist/client # Copy files to server directory cp server/package.json server/yarn.lock server/README.md dist/server -# Copy files to syntaxes directory +# Build and copy files to syntaxes directory +node syntaxes/out/build.js mkdir dist/syntaxes +cp syntaxes/out/*.json dist/syntaxes +# TODO: Remove the next two lines once all syntaxes have been refactored to TypeScript cp syntaxes/*.json dist/syntaxes +rm dist/syntaxes/tsconfig.json pushd dist yarn install --production --ignore-scripts diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index bc632af089..22ab2e4c77 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -5,3 +5,4 @@ set -ex -o pipefail # Clean up from last build rm -rf client/out rm -rf server/out +rm -rf syntaxes/out diff --git a/syntaxes/src/build.ts b/syntaxes/src/build.ts index b4d1f50e9e..296fa75af7 100644 --- a/syntaxes/src/build.ts +++ b/syntaxes/src/build.ts @@ -35,7 +35,7 @@ function build(grammar: GrammarDefinition, filename: string): void { const processedGrammar: JsonObject = processGrammar(grammar); const grammarContent: string = JSON.stringify(processedGrammar, null, ' ') + '\n'; - fs.writeFile(`syntaxes/${filename}.json`, grammarContent, (error) => { + fs.writeFile(`syntaxes/out/${filename}.json`, grammarContent, (error) => { if (error) throw error; }); } diff --git a/syntaxes/template.json b/syntaxes/template.json deleted file mode 100644 index fc39500adb..0000000000 --- a/syntaxes/template.json +++ /dev/null @@ -1,194 +0,0 @@ -{ - "scopeName": "template.ng", - "injectionSelector": "L:text.html -comment", - "patterns": [ - { - "include": "#interpolation" - }, - { - "include": "#propertyBinding" - }, - { - "include": "#eventBinding" - }, - { - "include": "#twoWayBinding" - }, - { - "include": "#templateBinding" - } - ], - "repository": { - "interpolation": { - "begin": "{{", - "beginCaptures": { - "0": { - "name": "punctuation.definition.block.ts" - } - }, - "end": "}}", - "endCaptures": { - "0": { - "name": "punctuation.definition.block.ts" - } - }, - "contentName": "source.js", - "patterns": [ - { - "include": "source.js" - } - ] - }, - "propertyBinding": { - "begin": "(\\[\\s*@?[-_a-zA-Z0-9.$]*\\s*])(=)([\"'])", - "beginCaptures": { - "1": { - "name": "entity.other.attribute-name.html entity.other.ng-binding-name.property.html", - "patterns": [ - { - "include": "#bindingKey" - } - ] - }, - "2": { - "name": "punctuation.separator.key-value.html" - }, - "3": { - "name": "string.quoted.html punctuation.definition.string.begin.html" - } - }, - "end": "\\3", - "endCaptures": { - "0": { - "name": "string.quoted.html punctuation.definition.string.end.html" - } - }, - "name": "meta.ng-binding.property.html", - "contentName": "source.js", - "patterns": [ - { - "include": "source.js" - } - ] - }, - "eventBinding": { - "begin": "(\\(\\s*@?[-_a-zA-Z0-9.$]*\\s*\\))(=)([\"'])", - "beginCaptures": { - "1": { - "name": "entity.other.attribute-name.html entity.other.ng-binding-name.event.html", - "patterns": [ - { - "include": "#bindingKey" - } - ] - }, - "2": { - "name": "punctuation.separator.key-value.html" - }, - "3": { - "name": "string.quoted.html punctuation.definition.string.begin.html" - } - }, - "end": "\\3", - "endCaptures": { - "0": { - "name": "string.quoted.html punctuation.definition.string.end.html" - } - }, - "name": "meta.ng-binding.event.html", - "contentName": "source.js", - "patterns": [ - { - "include": "source.js" - } - ] - }, - "twoWayBinding": { - "begin": "(\\[\\s*\\(\\s*@?[-_a-zA-Z0-9.$]*\\s*\\)\\s*\\])(=)([\"'])", - "beginCaptures": { - "1": { - "name": "entity.other.attribute-name.html entity.other.ng-binding-name.two-way.html", - "patterns": [ - { - "include": "#bindingKey" - } - ] - }, - "2": { - "name": "punctuation.separator.key-value.html" - }, - "3": { - "name": "string.quoted.html punctuation.definition.string.begin.html" - } - }, - "end": "\\3", - "endCaptures": { - "0": { - "name": "string.quoted.html punctuation.definition.string.end.html" - } - }, - "name": "meta.ng-binding.two-way.html", - "contentName": "source.js", - "patterns": [ - { - "include": "source.js" - } - ] - }, - "templateBinding": { - "begin": "(\\*[-_a-zA-Z0-9.$]*)(=)([\"'])", - "beginCaptures": { - "1": { - "name": "entity.other.attribute-name.html entity.other.ng-binding-name.template.html", - "patterns": [ - { - "include": "#bindingKey" - } - ] - }, - "2": { - "name": "punctuation.separator.key-value.html" - }, - "3": { - "name": "string.quoted.html punctuation.definition.string.begin.html" - } - }, - "end": "\\3", - "endCaptures": { - "0": { - "name": "string.quoted.html punctuation.definition.string.end.html" - } - }, - "name": "meta.ng-binding.template.html", - "contentName": "source.js", - "patterns": [ - { - "include": "source.js" - } - ] - }, - "bindingKey": { - "patterns": [ - { - "match": "([\\[\\(]{1,2})(?:\\s*)(@?[-_a-zA-Z0-9.$]*)(?:\\s*)([\\]\\)]{1,2})", - "captures": { - "1": { - "name": "punctuation.definition.ng-binding-name.begin.html" - }, - "2": { - "patterns": [ - { - "match": "\\.", - "name": "punctuation.accessor.html" - } - ] - }, - "3": { - "name": "punctuation.definition.ng-binding-name.end.html" - } - } - } - ] - } - } -} diff --git a/syntaxes/test/cases.json b/syntaxes/test/cases.json index 25ef81fddc..3c86929aeb 100644 --- a/syntaxes/test/cases.json +++ b/syntaxes/test/cases.json @@ -2,7 +2,7 @@ { "name": "inline template", "scopeName": "inline-template.ng", - "grammarFiles": ["syntaxes/inline-template.json", "syntaxes/template.json"], + "grammarFiles": ["syntaxes/inline-template.json", "syntaxes/out/template.json"], "testFile": "syntaxes/test/data/inline-template.ts" }, { @@ -14,7 +14,7 @@ { "name": "template syntax", "scopeName": "template.ng", - "grammarFiles": ["syntaxes/template.json"], + "grammarFiles": ["syntaxes/out/template.json"], "testFile": "syntaxes/test/data/template.html" } ] diff --git a/tsconfig.json b/tsconfig.json index bf09880226..7e5240c4cc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "files": [], "references": [ { "path": "./client" }, - { "path": "./server" } + { "path": "./server" }, + { "path": "./syntaxes" } ] } From 04546b355e852acb953f5be843260d77ae003778 Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Sun, 26 Jan 2020 16:04:36 -0500 Subject: [PATCH 15/16] Formatting --- syntaxes/test/cases.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/syntaxes/test/cases.json b/syntaxes/test/cases.json index 3c86929aeb..b4b6a96b9b 100644 --- a/syntaxes/test/cases.json +++ b/syntaxes/test/cases.json @@ -2,7 +2,10 @@ { "name": "inline template", "scopeName": "inline-template.ng", - "grammarFiles": ["syntaxes/inline-template.json", "syntaxes/out/template.json"], + "grammarFiles": [ + "syntaxes/inline-template.json", + "syntaxes/out/template.json" + ], "testFile": "syntaxes/test/data/inline-template.ts" }, { From a10718c5ca58282ffc5a090b737ae9bf0cc1756f Mon Sep 17 00:00:00 2001 From: dannymcgee Date: Mon, 27 Jan 2020 22:29:32 -0500 Subject: [PATCH 16/16] Consolidated Template grammar files --- syntaxes/src/template/grammar.ts | 140 ++++++++++++++++-- .../src/template/repository/binding-key.ts | 29 ---- .../src/template/repository/event-binding.ts | 32 ---- .../src/template/repository/interpolation.ts | 24 --- .../template/repository/property-binding.ts | 32 ---- .../template/repository/template-binding.ts | 32 ---- .../template/repository/two-way-binding.ts | 32 ---- 7 files changed, 127 insertions(+), 194 deletions(-) delete mode 100644 syntaxes/src/template/repository/binding-key.ts delete mode 100644 syntaxes/src/template/repository/event-binding.ts delete mode 100644 syntaxes/src/template/repository/interpolation.ts delete mode 100644 syntaxes/src/template/repository/property-binding.ts delete mode 100644 syntaxes/src/template/repository/template-binding.ts delete mode 100644 syntaxes/src/template/repository/two-way-binding.ts diff --git a/syntaxes/src/template/grammar.ts b/syntaxes/src/template/grammar.ts index d00226e20b..34af6e4f12 100644 --- a/syntaxes/src/template/grammar.ts +++ b/syntaxes/src/template/grammar.ts @@ -8,13 +8,6 @@ import {GrammarDefinition} from '../types'; -import {bindingKey} from './repository/binding-key'; -import {eventBinding} from './repository/event-binding'; -import {interpolation} from './repository/interpolation'; -import {propertyBinding} from './repository/property-binding'; -import {templateBinding} from './repository/template-binding'; -import {twoWayBinding} from './repository/two-way-binding'; - export const template: GrammarDefinition = { scopeName: 'template.ng', injectionSelector: 'L:text.html -comment', @@ -26,11 +19,132 @@ export const template: GrammarDefinition = { {include: '#templateBinding'}, ], repository: { - interpolation, - propertyBinding, - eventBinding, - twoWayBinding, - templateBinding, - bindingKey, + + interpolation: { + begin: /{{/, + beginCaptures: { + 0: {name: 'punctuation.definition.block.ts'}, + }, + end: /}}/, + endCaptures: { + 0: {name: 'punctuation.definition.block.ts'}, + }, + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], + }, + + propertyBinding: { + begin: /(\[\s*@?[-_a-zA-Z0-9.$]*\s*])(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.property.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.property.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], + }, + + eventBinding: { + begin: /(\(\s*@?[-_a-zA-Z0-9.$]*\s*\))(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.event.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.event.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], + }, + + twoWayBinding: { + begin: /(\[\s*\(\s*@?[-_a-zA-Z0-9.$]*\s*\)\s*\])(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.two-way.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.two-way.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], + }, + + templateBinding: { + begin: /(\*[-_a-zA-Z0-9.$]*)(=)(["'])/, + beginCaptures: { + 1: { + name: 'entity.other.attribute-name.html entity.other.ng-binding-name.template.html', + patterns: [ + {include: '#bindingKey'}, + ], + }, + 2: {name: 'punctuation.separator.key-value.html'}, + 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, + }, + end: /\3/, + endCaptures: { + 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, + }, + name: 'meta.ng-binding.template.html', + contentName: 'source.js', + patterns: [ + {include: 'source.js'}, + ], + }, + + bindingKey: { + patterns: [ + { + match: /([\[\(]{1,2})(?:\s*)(@?[-_a-zA-Z0-9.$]*)(?:\s*)([\]\)]{1,2})/, + captures: { + 1: {name: 'punctuation.definition.ng-binding-name.begin.html'}, + 2: { + patterns: [ + { + match: /\./, + name: 'punctuation.accessor.html', + }, + ], + }, + 3: {name: 'punctuation.definition.ng-binding-name.end.html'}, + }, + }, + ], + }, }, }; diff --git a/syntaxes/src/template/repository/binding-key.ts b/syntaxes/src/template/repository/binding-key.ts deleted file mode 100644 index 73f44819be..0000000000 --- a/syntaxes/src/template/repository/binding-key.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {GrammarDefinition} from '../../types'; - -export const bindingKey: GrammarDefinition = { - patterns: [ - { - match: /([\[\(]{1,2})(?:\s*)(@?[-_a-zA-Z0-9.$]*)(?:\s*)([\]\)]{1,2})/, - captures: { - 1: {name: 'punctuation.definition.ng-binding-name.begin.html'}, - 2: { - patterns: [ - { - match: /\./, - name: 'punctuation.accessor.html', - }, - ], - }, - 3: {name: 'punctuation.definition.ng-binding-name.end.html'}, - }, - }, - ], -}; diff --git a/syntaxes/src/template/repository/event-binding.ts b/syntaxes/src/template/repository/event-binding.ts deleted file mode 100644 index 534c27d694..0000000000 --- a/syntaxes/src/template/repository/event-binding.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {GrammarDefinition} from '../../types'; - -export const eventBinding: GrammarDefinition = { - begin: /(\(\s*@?[-_a-zA-Z0-9.$]*\s*\))(=)(["'])/, - beginCaptures: { - 1: { - name: 'entity.other.attribute-name.html entity.other.ng-binding-name.event.html', - patterns: [ - {include: '#bindingKey'}, - ], - }, - 2: {name: 'punctuation.separator.key-value.html'}, - 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, - }, - end: /\3/, - endCaptures: { - 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, - }, - name: 'meta.ng-binding.event.html', - contentName: 'source.js', - patterns: [ - {include: 'source.js'}, - ], -}; diff --git a/syntaxes/src/template/repository/interpolation.ts b/syntaxes/src/template/repository/interpolation.ts deleted file mode 100644 index add7964206..0000000000 --- a/syntaxes/src/template/repository/interpolation.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {GrammarDefinition} from '../../types'; - -export const interpolation: GrammarDefinition = { - begin: /{{/, - beginCaptures: { - 0: {name: 'punctuation.definition.block.ts'}, - }, - end: /}}/, - endCaptures: { - 0: {name: 'punctuation.definition.block.ts'}, - }, - contentName: 'source.js', - patterns: [ - {include: 'source.js'}, - ], -}; diff --git a/syntaxes/src/template/repository/property-binding.ts b/syntaxes/src/template/repository/property-binding.ts deleted file mode 100644 index 8a29ff0f6f..0000000000 --- a/syntaxes/src/template/repository/property-binding.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {GrammarDefinition} from '../../types'; - -export const propertyBinding: GrammarDefinition = { - begin: /(\[\s*@?[-_a-zA-Z0-9.$]*\s*])(=)(["'])/, - beginCaptures: { - 1: { - name: 'entity.other.attribute-name.html entity.other.ng-binding-name.property.html', - patterns: [ - {include: '#bindingKey'}, - ], - }, - 2: {name: 'punctuation.separator.key-value.html'}, - 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, - }, - end: /\3/, - endCaptures: { - 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, - }, - name: 'meta.ng-binding.property.html', - contentName: 'source.js', - patterns: [ - {include: 'source.js'}, - ], -}; diff --git a/syntaxes/src/template/repository/template-binding.ts b/syntaxes/src/template/repository/template-binding.ts deleted file mode 100644 index c8595cae5a..0000000000 --- a/syntaxes/src/template/repository/template-binding.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {GrammarDefinition} from '../../types'; - -export const templateBinding: GrammarDefinition = { - begin: /(\*[-_a-zA-Z0-9.$]*)(=)(["'])/, - beginCaptures: { - 1: { - name: 'entity.other.attribute-name.html entity.other.ng-binding-name.template.html', - patterns: [ - {include: '#bindingKey'}, - ], - }, - 2: {name: 'punctuation.separator.key-value.html'}, - 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, - }, - end: /\3/, - endCaptures: { - 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, - }, - name: 'meta.ng-binding.template.html', - contentName: 'source.js', - patterns: [ - {include: 'source.js'}, - ], -}; diff --git a/syntaxes/src/template/repository/two-way-binding.ts b/syntaxes/src/template/repository/two-way-binding.ts deleted file mode 100644 index 34983d7149..0000000000 --- a/syntaxes/src/template/repository/two-way-binding.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {GrammarDefinition} from '../../types'; - -export const twoWayBinding: GrammarDefinition = { - begin: /(\[\s*\(\s*@?[-_a-zA-Z0-9.$]*\s*\)\s*\])(=)(["'])/, - beginCaptures: { - 1: { - name: 'entity.other.attribute-name.html entity.other.ng-binding-name.two-way.html', - patterns: [ - {include: '#bindingKey'}, - ], - }, - 2: {name: 'punctuation.separator.key-value.html'}, - 3: {name: 'string.quoted.html punctuation.definition.string.begin.html'}, - }, - end: /\3/, - endCaptures: { - 0: {name: 'string.quoted.html punctuation.definition.string.end.html'}, - }, - name: 'meta.ng-binding.two-way.html', - contentName: 'source.js', - patterns: [ - {include: 'source.js'}, - ], -};