@@ -19,7 +19,7 @@ function file(language: Language, extension: Extension) {
19
19
return path.join(__dirname, '..', `${language}.${extension}`);
20
20
}
21
21
22
- function writePlistFile(grammar: any , fileName: string) {
22
+ function writePlistFile(grammar: TmGrammar | TmTheme , fileName: string) {
23
23
const text = plist.build(grammar);
24
24
fs.writeFileSync(fileName, text);
25
25
}
@@ -35,29 +35,30 @@ function changeTsToTsx(str: string) {
35
35
36
36
function transformGrammarRule(rule: any, propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
37
37
for (const propertyName of propertyNames) {
38
- if (typeof rule[propertyName] === 'string') {
39
- rule[propertyName] = transformProperty(rule[propertyName]);
38
+ const value = rule[propertyName];
39
+ if (typeof value === 'string') {
40
+ rule[propertyName] = transformProperty(value);
40
41
}
41
42
}
42
43
43
44
for (var propertyName in rule) {
44
- var value = rule[propertyName];
45
+ const value = rule[propertyName];
45
46
if (typeof value === 'object') {
46
47
transformGrammarRule(value, propertyNames, transformProperty);
47
48
}
48
49
}
49
50
}
50
51
51
- function transformGrammarRepository(grammar: any , propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
52
+ function transformGrammarRepository(grammar: TmGrammar , propertyNames: string[], transformProperty: (ruleProperty: string) => string) {
52
53
const repository = grammar.repository;
53
54
for (let key in repository) {
54
55
transformGrammarRule(repository[key], propertyNames, transformProperty);
55
56
}
56
57
}
57
58
58
59
function getTsxGrammar() {
59
- let variables: any ;
60
- const tsxUpdatesBeforeTransformation = readYaml(file(Language.TypeScriptReact, Extension.YamlTmLangauge));
60
+ let variables: MapLike<string> ;
61
+ const tsxUpdatesBeforeTransformation = readYaml(file(Language.TypeScriptReact, Extension.YamlTmLangauge)) as TmGrammar ;
61
62
const grammar = getTsGrammar(tsGrammarVariables => {
62
63
variables = tsGrammarVariables;
63
64
for (const variableName in tsxUpdatesBeforeTransformation.variables) {
@@ -68,11 +69,10 @@ function getTsxGrammar() {
68
69
const tsxUpdates = updateGrammarVariables(tsxUpdatesBeforeTransformation, variables);
69
70
70
71
// Update name, file types, scope name and uuid
71
- for (let key in tsxUpdates) {
72
- if (key !== "repository") {
73
- grammar[key] = tsxUpdates[key];
74
- }
75
- }
72
+ grammar.name = tsxUpdates.name;
73
+ grammar.scopeName = tsxUpdates.scopeName;
74
+ grammar.fileTypes = tsxUpdates.fileTypes;
75
+ grammar.uuid = tsxUpdates.uuid;
76
76
77
77
// Update scope names to .tsx
78
78
transformGrammarRepository(grammar, ["name", "contentName"], changeTsToTsx);
@@ -84,7 +84,7 @@ function getTsxGrammar() {
84
84
switch(key) {
85
85
case "expressionWithoutIdentifiers":
86
86
// Update expression
87
- repository[key].patterns.unshift(updatesRepository[key].patterns[0]);
87
+ ( repository[key] as TmGrammarRepositoryPatterns) .patterns.unshift(( updatesRepository[key] as TmGrammarRepositoryPatterns) .patterns[0]);
88
88
break;
89
89
default:
90
90
// Add jsx
@@ -95,8 +95,8 @@ function getTsxGrammar() {
95
95
return grammar;
96
96
}
97
97
98
- function getTsGrammar(getVariables: (tsGrammarVariables: any ) => any ) {
99
- const tsGrammarBeforeTransformation = readYaml(file(Language.TypeScript, Extension.YamlTmLangauge));
98
+ function getTsGrammar(getVariables: (tsGrammarVariables: MapLike<string> ) => MapLike<string> ) {
99
+ const tsGrammarBeforeTransformation = readYaml(file(Language.TypeScript, Extension.YamlTmLangauge)) as TmGrammar ;
100
100
return updateGrammarVariables(tsGrammarBeforeTransformation, getVariables(tsGrammarBeforeTransformation.variables));
101
101
}
102
102
@@ -109,7 +109,7 @@ function replacePatternVariables(pattern: string, variableReplacers: VariableRep
109
109
}
110
110
111
111
type VariableReplacer = [RegExp, string];
112
- function updateGrammarVariables(grammar: any , variables: any ) {
112
+ function updateGrammarVariables(grammar: TmGrammar , variables: MapLike<string> ) {
113
113
delete grammar.variables;
114
114
const variableReplacers: VariableReplacer[] = [];
115
115
for (const variableName in variables) {
@@ -136,15 +136,12 @@ function buildGrammar() {
136
136
writePlistFile(tsxGrammar, file(Language.TypeScriptReact, Extension.TmLanguage));
137
137
}
138
138
139
- function changeTsToTsxTheme(theme: any ) {
140
- const tsxUpdates = readYaml(file(Language.TypeScriptReact, Extension.YamlTmTheme));
139
+ function changeTsToTsxTheme(theme: TmTheme ) {
140
+ const tsxUpdates = readYaml(file(Language.TypeScriptReact, Extension.YamlTmTheme)) as TmTheme ;
141
141
142
142
// Update name, uuid
143
- for (let key in tsxUpdates) {
144
- if (key !== "settings") {
145
- theme[key] = tsxUpdates[key];
146
- }
147
- }
143
+ theme.name = tsxUpdates.name;
144
+ theme.uuid = tsxUpdates.uuid;
148
145
149
146
// Update scope names to .tsx
150
147
const settings = theme.settings;
@@ -159,7 +156,7 @@ function changeTsToTsxTheme(theme: any) {
159
156
}
160
157
161
158
function buildTheme() {
162
- const tsTheme = readYaml(file(Language.TypeScript, Extension.YamlTmTheme));
159
+ const tsTheme = readYaml(file(Language.TypeScript, Extension.YamlTmTheme)) as TmTheme ;
163
160
164
161
// Write TypeScript.tmTheme
165
162
writePlistFile(tsTheme, file(Language.TypeScript, Extension.TmTheme));
0 commit comments