brighterscript 1.0.0-alpha.47 → 1.0.0-alpha.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -10
- package/bsconfig.schema.json +34 -7
- package/dist/AstValidationSegmenter.js +21 -3
- package/dist/AstValidationSegmenter.js.map +1 -1
- package/dist/BsConfig.d.ts +6 -35
- package/dist/CrossScopeValidator.d.ts +1 -0
- package/dist/CrossScopeValidator.js +28 -4
- package/dist/CrossScopeValidator.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +1 -1
- package/dist/DiagnosticMessages.js +20 -6
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +22 -6
- package/dist/LanguageServer.js +62 -25
- package/dist/LanguageServer.js.map +1 -1
- package/dist/PluginInterface.js +4 -1
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +9 -3
- package/dist/Program.js +111 -74
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +0 -2
- package/dist/ProgramBuilder.js +10 -28
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/SymbolTable.js +3 -2
- package/dist/SymbolTable.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +14 -2
- package/dist/astUtils/reflection.js +70 -18
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +2 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js +9 -3
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +3 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +34 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +31 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +10 -4
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +17 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +5 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +71 -3
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +7 -7
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +43 -14
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +99 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +19 -4
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +372 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
- package/dist/cli.js +11 -18
- package/dist/cli.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +336 -200
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.spec.js +168 -10
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +7 -0
- package/dist/files/XmlFile.js +36 -0
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +7 -9
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +3 -3
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +1 -1
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/interfaces.d.ts +12 -4
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +12 -2
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.js +6 -3
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/lsp/LspProject.d.ts +17 -9
- package/dist/lsp/Project.d.ts +8 -7
- package/dist/lsp/Project.js +21 -23
- package/dist/lsp/Project.js.map +1 -1
- package/dist/lsp/Project.spec.js +44 -12
- package/dist/lsp/Project.spec.js.map +1 -1
- package/dist/lsp/ProjectManager.d.ts +31 -10
- package/dist/lsp/ProjectManager.js +130 -60
- package/dist/lsp/ProjectManager.js.map +1 -1
- package/dist/lsp/ProjectManager.spec.js +245 -115
- package/dist/lsp/ProjectManager.spec.js.map +1 -1
- package/dist/lsp/worker/WorkerThreadProject.d.ts +6 -7
- package/dist/lsp/worker/WorkerThreadProject.js +27 -21
- package/dist/lsp/worker/WorkerThreadProject.js.map +1 -1
- package/dist/lsp/worker/WorkerThreadProject.spec.js +4 -1
- package/dist/lsp/worker/WorkerThreadProject.spec.js.map +1 -1
- package/dist/lsp/worker/run.d.ts +1 -0
- package/dist/lsp/worker/run.js +14 -0
- package/dist/lsp/worker/run.js.map +1 -0
- package/dist/parser/AstNode.d.ts +8 -1
- package/dist/parser/AstNode.js +9 -0
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/AstNode.spec.js +1 -1
- package/dist/parser/AstNode.spec.js.map +1 -1
- package/dist/parser/Expression.d.ts +43 -0
- package/dist/parser/Expression.js +120 -7
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +25 -0
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +4 -0
- package/dist/parser/Parser.js +117 -7
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +200 -1
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +32 -1
- package/dist/parser/Statement.js +128 -64
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +238 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/roku-types/data.json +422 -64
- package/dist/roku-types/index.d.ts +50 -0
- package/dist/types/ArrayType.js +3 -0
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/BscType.d.ts +4 -3
- package/dist/types/BscType.js +2 -4
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BscTypeKind.d.ts +2 -0
- package/dist/types/BscTypeKind.js +2 -0
- package/dist/types/BscTypeKind.js.map +1 -1
- package/dist/types/CallFuncableType.d.ts +24 -0
- package/dist/types/CallFuncableType.js +91 -0
- package/dist/types/CallFuncableType.js.map +1 -0
- package/dist/types/ComponentType.d.ts +3 -15
- package/dist/types/ComponentType.js +2 -56
- package/dist/types/ComponentType.js.map +1 -1
- package/dist/types/DoubleType.js +1 -1
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/FloatType.js +1 -1
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/InlineInterfaceType.d.ts +5 -0
- package/dist/types/InlineInterfaceType.js +17 -0
- package/dist/types/InlineInterfaceType.js.map +1 -0
- package/dist/types/IntegerType.js +1 -1
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +2 -2
- package/dist/types/InterfaceType.js +5 -4
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/LongIntegerType.js +1 -1
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +1 -0
- package/dist/types/ObjectType.js +3 -0
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ReferenceType.d.ts +3 -2
- package/dist/types/ReferenceType.js +54 -22
- package/dist/types/ReferenceType.js.map +1 -1
- package/dist/types/TypeStatementType.d.ts +18 -0
- package/dist/types/TypeStatementType.js +45 -0
- package/dist/types/TypeStatementType.js.map +1 -0
- package/dist/types/UnionType.d.ts +3 -0
- package/dist/types/UnionType.js +7 -0
- package/dist/types/UnionType.js.map +1 -1
- package/dist/types/UnionType.spec.js +43 -0
- package/dist/types/UnionType.spec.js.map +1 -1
- package/dist/types/roFunctionType.d.ts +11 -0
- package/dist/types/roFunctionType.js +37 -0
- package/dist/types/roFunctionType.js.map +1 -0
- package/dist/types/roFunctionType.spec.d.ts +1 -0
- package/dist/types/roFunctionType.spec.js +20 -0
- package/dist/types/roFunctionType.spec.js.map +1 -0
- package/dist/util.d.ts +9 -94
- package/dist/util.js +67 -305
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +1 -1
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +3 -3
package/dist/util.js
CHANGED
|
@@ -8,7 +8,6 @@ const path = require("path");
|
|
|
8
8
|
const roku_deploy_1 = require("roku-deploy");
|
|
9
9
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
10
10
|
const vscode_uri_1 = require("vscode-uri");
|
|
11
|
-
const xml2js = require("xml2js");
|
|
12
11
|
const DiagnosticMessages_1 = require("./DiagnosticMessages");
|
|
13
12
|
const interfaces_1 = require("./interfaces");
|
|
14
13
|
const BooleanType_1 = require("./types/BooleanType");
|
|
@@ -125,29 +124,6 @@ class Util {
|
|
|
125
124
|
//ensure every path has the leading pkg:/
|
|
126
125
|
return 'pkg:/' + pkgPath.replace(/^pkg:\//i, '');
|
|
127
126
|
}
|
|
128
|
-
/**
|
|
129
|
-
* Determine if the given path starts with a protocol
|
|
130
|
-
*/
|
|
131
|
-
startsWithProtocol(path) {
|
|
132
|
-
return !!/^[-a-z]+:\//i.exec(path);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Given a pkg path of any kind, transform it to a roku-specific pkg path (i.e. "pkg:/some/path.brs")
|
|
136
|
-
* @deprecated use `sanitizePkgPath instead. Will be removed in v1
|
|
137
|
-
*/
|
|
138
|
-
getRokuPkgPath(pkgPath) {
|
|
139
|
-
return this.sanitizePkgPath(pkgPath);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Given a path to a file/directory, replace all path separators with the current system's version.
|
|
143
|
-
*/
|
|
144
|
-
pathSepNormalize(filePath, separator) {
|
|
145
|
-
if (!filePath) {
|
|
146
|
-
return filePath;
|
|
147
|
-
}
|
|
148
|
-
separator = separator ? separator : path.sep;
|
|
149
|
-
return filePath.replace(/[\\/]+/g, separator);
|
|
150
|
-
}
|
|
151
127
|
/**
|
|
152
128
|
* Find the path to the config file.
|
|
153
129
|
* If the config file path doesn't exist
|
|
@@ -247,18 +223,15 @@ class Util {
|
|
|
247
223
|
result._ancestors = parentProjectPaths;
|
|
248
224
|
}
|
|
249
225
|
//make any paths in the config absolute (relative to the CURRENT config file)
|
|
250
|
-
if (result.outFile) {
|
|
251
|
-
result.outFile = path.resolve(projectFileCwd, result.outFile);
|
|
252
|
-
}
|
|
253
226
|
if (result.rootDir) {
|
|
254
227
|
result.rootDir = path.resolve(projectFileCwd, result.rootDir);
|
|
255
228
|
}
|
|
229
|
+
if (result.outDir) {
|
|
230
|
+
result.outDir = path.resolve(projectFileCwd, result.outDir);
|
|
231
|
+
}
|
|
256
232
|
if (result.cwd) {
|
|
257
233
|
result.cwd = path.resolve(projectFileCwd, result.cwd);
|
|
258
234
|
}
|
|
259
|
-
if (result.stagingDir) {
|
|
260
|
-
result.stagingDir = path.resolve(projectFileCwd, result.stagingDir);
|
|
261
|
-
}
|
|
262
235
|
if (result.sourceRoot && result.resolveSourceRoot) {
|
|
263
236
|
result.sourceRoot = path.resolve(projectFileCwd, result.sourceRoot);
|
|
264
237
|
}
|
|
@@ -284,35 +257,6 @@ class Util {
|
|
|
284
257
|
}
|
|
285
258
|
collection[key] = [...result];
|
|
286
259
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Do work within the scope of a changed current working directory
|
|
289
|
-
* @param targetCwd the cwd where the work should be performed
|
|
290
|
-
* @param callback a function to call when the cwd has been changed to `targetCwd`
|
|
291
|
-
*/
|
|
292
|
-
cwdWork(targetCwd, callback) {
|
|
293
|
-
let originalCwd = process.cwd();
|
|
294
|
-
if (targetCwd) {
|
|
295
|
-
process.chdir(targetCwd);
|
|
296
|
-
}
|
|
297
|
-
let result;
|
|
298
|
-
let err;
|
|
299
|
-
try {
|
|
300
|
-
result = callback();
|
|
301
|
-
}
|
|
302
|
-
catch (e) {
|
|
303
|
-
err = e;
|
|
304
|
-
}
|
|
305
|
-
if (targetCwd) {
|
|
306
|
-
process.chdir(originalCwd);
|
|
307
|
-
}
|
|
308
|
-
if (err) {
|
|
309
|
-
throw err;
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
//justification: `result` is set as long as `err` is not set and vice versa
|
|
313
|
-
return result;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
260
|
/**
|
|
317
261
|
* Given a BsConfig object, start with defaults,
|
|
318
262
|
* merge with bsconfig.json and the provided options.
|
|
@@ -344,38 +288,55 @@ class Util {
|
|
|
344
288
|
* @param config a bsconfig object to use as the baseline for the resulting config
|
|
345
289
|
*/
|
|
346
290
|
normalizeConfig(config) {
|
|
347
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
291
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
348
292
|
config = config !== null && config !== void 0 ? config : {};
|
|
349
293
|
const cwd = (_a = config.cwd) !== null && _a !== void 0 ? _a : process.cwd();
|
|
350
|
-
const rootFolderName = path.basename(cwd);
|
|
351
|
-
const retainStagingDir = ((_b = config.retainStagingDir) !== null && _b !== void 0 ? _b : config.retainStagingDir) === true ? true : false;
|
|
352
294
|
let logLevel = logging_1.LogLevel.log;
|
|
353
295
|
if (typeof config.logLevel === 'string') {
|
|
354
|
-
logLevel = (
|
|
296
|
+
logLevel = (_b = logging_1.LogLevel[config.logLevel.toLowerCase()]) !== null && _b !== void 0 ? _b : logging_1.LogLevel.log;
|
|
355
297
|
}
|
|
356
|
-
let bslibDestinationDir = (
|
|
298
|
+
let bslibDestinationDir = (_c = config.bslibDestinationDir) !== null && _c !== void 0 ? _c : 'source';
|
|
357
299
|
if (bslibDestinationDir !== 'source') {
|
|
358
300
|
// strip leading and trailing slashes
|
|
359
301
|
bslibDestinationDir = bslibDestinationDir.replace(/^(\/*)(.*?)(\/*)$/, '$2');
|
|
360
302
|
}
|
|
303
|
+
let noEmit;
|
|
304
|
+
if ('noEmit' in config) {
|
|
305
|
+
noEmit = config.noEmit;
|
|
306
|
+
}
|
|
307
|
+
else if ('copyToStaging' in config) {
|
|
308
|
+
noEmit = !config.copyToStaging; //invert the old value
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
noEmit = false; //default case
|
|
312
|
+
}
|
|
313
|
+
let outDir;
|
|
314
|
+
if ('outDir' in config) {
|
|
315
|
+
outDir = (_d = config.outDir) !== null && _d !== void 0 ? _d : './out';
|
|
316
|
+
}
|
|
317
|
+
else if ('stagingFolderPath' in config) {
|
|
318
|
+
outDir = config.stagingFolderPath;
|
|
319
|
+
}
|
|
320
|
+
else if ('stagingDir' in config) {
|
|
321
|
+
outDir = config.stagingDir;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
outDir = './out'; //default case
|
|
325
|
+
}
|
|
361
326
|
const configWithDefaults = {
|
|
362
327
|
cwd: cwd,
|
|
363
|
-
deploy: config.deploy === true ? true : false,
|
|
364
328
|
//use default files array from rokuDeploy
|
|
365
329
|
files: (_e = config.files) !== null && _e !== void 0 ? _e : [...roku_deploy_1.DefaultFiles],
|
|
366
|
-
|
|
367
|
-
outFile: (_f = config.outFile) !== null && _f !== void 0 ? _f : `./out/${rootFolderName}.zip`,
|
|
330
|
+
outDir: outDir,
|
|
368
331
|
sourceMap: config.sourceMap === true,
|
|
369
|
-
username: (_g = config.username) !== null && _g !== void 0 ? _g : 'rokudev',
|
|
370
332
|
watch: config.watch === true ? true : false,
|
|
371
333
|
emitFullPaths: config.emitFullPaths === true ? true : false,
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
diagnosticFilters: (_k = config.diagnosticFilters) !== null && _k !== void 0 ? _k : [],
|
|
334
|
+
noEmit: noEmit,
|
|
335
|
+
ignoreErrorCodes: (_f = config.ignoreErrorCodes) !== null && _f !== void 0 ? _f : [],
|
|
336
|
+
diagnosticSeverityOverrides: (_g = config.diagnosticSeverityOverrides) !== null && _g !== void 0 ? _g : {},
|
|
337
|
+
diagnosticFilters: (_h = config.diagnosticFilters) !== null && _h !== void 0 ? _h : [],
|
|
377
338
|
diagnosticFiltersV0Compatibility: config.diagnosticFiltersV0Compatibility === true ? true : false,
|
|
378
|
-
plugins: (
|
|
339
|
+
plugins: (_j = config.plugins) !== null && _j !== void 0 ? _j : [],
|
|
379
340
|
pruneEmptyCodeFiles: config.pruneEmptyCodeFiles === true ? true : false,
|
|
380
341
|
autoImportComponentScript: config.autoImportComponentScript === true ? true : false,
|
|
381
342
|
showDiagnosticsInConsole: config.showDiagnosticsInConsole === false ? false : true,
|
|
@@ -427,12 +388,6 @@ class Util {
|
|
|
427
388
|
}
|
|
428
389
|
return result;
|
|
429
390
|
}
|
|
430
|
-
/**
|
|
431
|
-
* Split a file by newline characters (LF or CRLF)
|
|
432
|
-
*/
|
|
433
|
-
getLines(text) {
|
|
434
|
-
return text.split(/\r?\n/);
|
|
435
|
-
}
|
|
436
391
|
/**
|
|
437
392
|
* Given an absolute path to a source file, and a target path,
|
|
438
393
|
* compute the pkg path for the target relative to the source file's location
|
|
@@ -713,37 +668,6 @@ class Util {
|
|
|
713
668
|
getSgNodeTypeName(sgNodeName) {
|
|
714
669
|
return 'roSGNode' + sgNodeName;
|
|
715
670
|
}
|
|
716
|
-
/**
|
|
717
|
-
* Parse an xml file and get back a javascript object containing its results
|
|
718
|
-
*/
|
|
719
|
-
parseXml(text) {
|
|
720
|
-
return new Promise((resolve, reject) => {
|
|
721
|
-
xml2js.parseString(text, (err, data) => {
|
|
722
|
-
if (err) {
|
|
723
|
-
reject(err);
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
resolve(data);
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
propertyCount(object) {
|
|
732
|
-
let count = 0;
|
|
733
|
-
for (let key in object) {
|
|
734
|
-
if (object.hasOwnProperty(key)) {
|
|
735
|
-
count++;
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return count;
|
|
739
|
-
}
|
|
740
|
-
padLeft(subject, totalLength, char) {
|
|
741
|
-
totalLength = totalLength > 1000 ? 1000 : totalLength;
|
|
742
|
-
while (subject.length < totalLength) {
|
|
743
|
-
subject = char + subject;
|
|
744
|
-
}
|
|
745
|
-
return subject;
|
|
746
|
-
}
|
|
747
671
|
/**
|
|
748
672
|
* Force the drive letter to lower case
|
|
749
673
|
*/
|
|
@@ -773,21 +697,6 @@ class Util {
|
|
|
773
697
|
return subject;
|
|
774
698
|
}
|
|
775
699
|
}
|
|
776
|
-
/**
|
|
777
|
-
* Determine if two arrays containing primitive values are equal.
|
|
778
|
-
* This considers order and compares by equality.
|
|
779
|
-
*/
|
|
780
|
-
areArraysEqual(arr1, arr2) {
|
|
781
|
-
if (arr1.length !== arr2.length) {
|
|
782
|
-
return false;
|
|
783
|
-
}
|
|
784
|
-
for (let i = 0; i < arr1.length; i++) {
|
|
785
|
-
if (arr1[i] !== arr2[i]) {
|
|
786
|
-
return false;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
return true;
|
|
790
|
-
}
|
|
791
700
|
/**
|
|
792
701
|
* Does the string appear to be a uri (i.e. does it start with `file:`)
|
|
793
702
|
*/
|
|
@@ -826,19 +735,6 @@ class Util {
|
|
|
826
735
|
const normalizedPath = path.normalize(parsedPath);
|
|
827
736
|
return normalizedPath;
|
|
828
737
|
}
|
|
829
|
-
/**
|
|
830
|
-
* Get the outDir from options, taking into account cwd and absolute outFile paths
|
|
831
|
-
*/
|
|
832
|
-
getOutDir(options) {
|
|
833
|
-
options = this.normalizeConfig(options);
|
|
834
|
-
let cwd = path.normalize(options.cwd ? options.cwd : process.cwd());
|
|
835
|
-
if (path.isAbsolute(options.outFile)) {
|
|
836
|
-
return path.dirname(options.outFile);
|
|
837
|
-
}
|
|
838
|
-
else {
|
|
839
|
-
return path.normalize(path.join(cwd, path.dirname(options.outFile)));
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
738
|
/**
|
|
843
739
|
* Get paths to all files on disc that match this project's source list
|
|
844
740
|
*/
|
|
@@ -862,31 +758,6 @@ class Util {
|
|
|
862
758
|
return undefined;
|
|
863
759
|
}
|
|
864
760
|
}
|
|
865
|
-
/**
|
|
866
|
-
* Walks up the chain to find the closest bsconfig.json file
|
|
867
|
-
*/
|
|
868
|
-
async findClosestConfigFile(currentPath) {
|
|
869
|
-
//make the path absolute
|
|
870
|
-
currentPath = path.resolve(path.normalize(currentPath));
|
|
871
|
-
let previousPath;
|
|
872
|
-
//using ../ on the root of the drive results in the same file path, so that's how we know we reached the top
|
|
873
|
-
while (previousPath !== currentPath) {
|
|
874
|
-
previousPath = currentPath;
|
|
875
|
-
let bsPath = path.join(currentPath, 'bsconfig.json');
|
|
876
|
-
let brsPath = path.join(currentPath, 'brsconfig.json');
|
|
877
|
-
if (await this.pathExists(bsPath)) {
|
|
878
|
-
return bsPath;
|
|
879
|
-
}
|
|
880
|
-
else if (await this.pathExists(brsPath)) {
|
|
881
|
-
return brsPath;
|
|
882
|
-
}
|
|
883
|
-
else {
|
|
884
|
-
//walk upwards one directory
|
|
885
|
-
currentPath = path.resolve(path.join(currentPath, '../'));
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
//got to the root path, no config file exists
|
|
889
|
-
}
|
|
890
761
|
/**
|
|
891
762
|
* Set a timeout for the specified milliseconds, and resolve the promise once the timeout is finished.
|
|
892
763
|
* @param milliseconds the minimum number of milliseconds to sleep for
|
|
@@ -902,14 +773,6 @@ class Util {
|
|
|
902
773
|
}
|
|
903
774
|
});
|
|
904
775
|
}
|
|
905
|
-
/**
|
|
906
|
-
* Given an array, map and then flatten
|
|
907
|
-
* @param array the array to flatMap over
|
|
908
|
-
* @param callback a function that is called for every array item
|
|
909
|
-
*/
|
|
910
|
-
flatMap(array, callback) {
|
|
911
|
-
return Array.prototype.concat.apply([], array.map(callback));
|
|
912
|
-
}
|
|
913
776
|
/**
|
|
914
777
|
* Determines if the position is greater than the range. This means
|
|
915
778
|
* the position does not touch the range, and has a position greater than the end
|
|
@@ -954,27 +817,6 @@ class Util {
|
|
|
954
817
|
return undefined;
|
|
955
818
|
}
|
|
956
819
|
}
|
|
957
|
-
/**
|
|
958
|
-
* Get a location object back by extracting location information from other objects that contain location
|
|
959
|
-
*/
|
|
960
|
-
getRange(startObj, endObj) {
|
|
961
|
-
var _a, _b;
|
|
962
|
-
if (!(startObj === null || startObj === void 0 ? void 0 : startObj.range) || !(endObj === null || endObj === void 0 ? void 0 : endObj.range)) {
|
|
963
|
-
return undefined;
|
|
964
|
-
}
|
|
965
|
-
return exports.util.createRangeFromPositions((_a = startObj.range) === null || _a === void 0 ? void 0 : _a.start, (_b = endObj.range) === null || _b === void 0 ? void 0 : _b.end);
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* If the two items both start on the same line
|
|
969
|
-
*/
|
|
970
|
-
sameStartLine(first, second) {
|
|
971
|
-
if (first && second && first.range.start.line === second.range.start.line) {
|
|
972
|
-
return true;
|
|
973
|
-
}
|
|
974
|
-
else {
|
|
975
|
-
return false;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
820
|
/**
|
|
979
821
|
* If the two items have lines that touch
|
|
980
822
|
*/
|
|
@@ -991,18 +833,6 @@ class Util {
|
|
|
991
833
|
return false;
|
|
992
834
|
}
|
|
993
835
|
}
|
|
994
|
-
/**
|
|
995
|
-
* Given text with (or without) dots separating text, get the rightmost word.
|
|
996
|
-
* (i.e. given "A.B.C", returns "C". or "B" returns "B because there's no dot)
|
|
997
|
-
*/
|
|
998
|
-
getTextAfterFinalDot(name) {
|
|
999
|
-
if (name) {
|
|
1000
|
-
let parts = name.split('.');
|
|
1001
|
-
if (parts.length > 0) {
|
|
1002
|
-
return parts[parts.length - 1];
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
836
|
/**
|
|
1007
837
|
* Find a script import that the current position touches, or undefined if not found
|
|
1008
838
|
*/
|
|
@@ -1275,17 +1105,6 @@ class Util {
|
|
|
1275
1105
|
character: character
|
|
1276
1106
|
};
|
|
1277
1107
|
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Convert a list of tokens into a string, including their leading whitespace
|
|
1280
|
-
*/
|
|
1281
|
-
tokensToString(tokens) {
|
|
1282
|
-
let result = '';
|
|
1283
|
-
//skip iterating the final token
|
|
1284
|
-
for (let token of tokens) {
|
|
1285
|
-
result += token.leadingWhitespace + token.text;
|
|
1286
|
-
}
|
|
1287
|
-
return result;
|
|
1288
|
-
}
|
|
1289
1108
|
/**
|
|
1290
1109
|
* Convert a token into a BscType
|
|
1291
1110
|
*/
|
|
@@ -1548,12 +1367,12 @@ class Util {
|
|
|
1548
1367
|
let hasInvalid = (0, reflection_1.isInvalidTypeLike)(leftType) || (0, reflection_1.isInvalidTypeLike)(rightType);
|
|
1549
1368
|
let hasDynamic = (0, reflection_1.isDynamicType)(leftType) || (0, reflection_1.isDynamicType)(rightType);
|
|
1550
1369
|
let bothDynamic = (0, reflection_1.isDynamicType)(leftType) && (0, reflection_1.isDynamicType)(rightType);
|
|
1551
|
-
let bothNumbers = (0, reflection_1.
|
|
1552
|
-
let hasNumber = (0, reflection_1.
|
|
1370
|
+
let bothNumbers = (0, reflection_1.isNumberTypeLike)(leftType) && (0, reflection_1.isNumberTypeLike)(rightType);
|
|
1371
|
+
let hasNumber = (0, reflection_1.isNumberTypeLike)(leftType) || (0, reflection_1.isNumberTypeLike)(rightType);
|
|
1553
1372
|
let bothStrings = (0, reflection_1.isStringTypeLike)(leftType) && (0, reflection_1.isStringTypeLike)(rightType);
|
|
1554
1373
|
let hasString = (0, reflection_1.isStringTypeLike)(leftType) || (0, reflection_1.isStringTypeLike)(rightType);
|
|
1555
1374
|
let hasBoolean = (0, reflection_1.isBooleanTypeLike)(leftType) || (0, reflection_1.isBooleanTypeLike)(rightType);
|
|
1556
|
-
let eitherBooleanOrNum = ((0, reflection_1.
|
|
1375
|
+
let eitherBooleanOrNum = ((0, reflection_1.isNumberTypeLike)(leftType) || (0, reflection_1.isBooleanTypeLike)(leftType)) && ((0, reflection_1.isNumberTypeLike)(rightType) || (0, reflection_1.isBooleanTypeLike)(rightType));
|
|
1557
1376
|
let leftIsPrimitive = (0, reflection_1.isPrimitiveType)(leftType);
|
|
1558
1377
|
let rightIsPrimitive = (0, reflection_1.isPrimitiveType)(rightType);
|
|
1559
1378
|
let hasPrimitive = leftIsPrimitive || rightIsPrimitive;
|
|
@@ -1774,7 +1593,7 @@ class Util {
|
|
|
1774
1593
|
// Math operators
|
|
1775
1594
|
case TokenKind_1.TokenKind.Plus: // (`num = +num` is valid syntax)
|
|
1776
1595
|
case TokenKind_1.TokenKind.Minus:
|
|
1777
|
-
if ((0, reflection_1.
|
|
1596
|
+
if ((0, reflection_1.isNumberTypeLike)(exprType)) {
|
|
1778
1597
|
// a negative number will be the same type, eg, double->double, int->int, etc.
|
|
1779
1598
|
return this.getUnboxedType(exprType);
|
|
1780
1599
|
}
|
|
@@ -1783,7 +1602,7 @@ class Util {
|
|
|
1783
1602
|
if ((0, reflection_1.isBooleanTypeLike)(exprType)) {
|
|
1784
1603
|
return BooleanType_1.BooleanType.instance;
|
|
1785
1604
|
}
|
|
1786
|
-
else if ((0, reflection_1.
|
|
1605
|
+
else if ((0, reflection_1.isNumberTypeLike)(exprType)) {
|
|
1787
1606
|
//numbers can be "notted"
|
|
1788
1607
|
// by default they go to ints, except longints, which stay that way
|
|
1789
1608
|
if ((0, reflection_1.isLongIntegerTypeLike)(exprType)) {
|
|
@@ -2010,19 +1829,6 @@ class Util {
|
|
|
2010
1829
|
}
|
|
2011
1830
|
return result;
|
|
2012
1831
|
}
|
|
2013
|
-
/**
|
|
2014
|
-
* Get the first locatable item found at the specified position
|
|
2015
|
-
* @param locatables an array of items that have a `range` property
|
|
2016
|
-
* @param position the position that the locatable must contain
|
|
2017
|
-
*/
|
|
2018
|
-
getFirstLocatableAt(locatables, position) {
|
|
2019
|
-
var _a;
|
|
2020
|
-
for (let token of locatables) {
|
|
2021
|
-
if (exports.util.rangeContains((_a = token.location) === null || _a === void 0 ? void 0 : _a.range, position)) {
|
|
2022
|
-
return token;
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
1832
|
/**
|
|
2027
1833
|
* Sort an array of objects that have a Range
|
|
2028
1834
|
*/
|
|
@@ -2067,26 +1873,6 @@ class Util {
|
|
|
2067
1873
|
return 0;
|
|
2068
1874
|
});
|
|
2069
1875
|
}
|
|
2070
|
-
/**
|
|
2071
|
-
* Split the given text and return ranges for each chunk.
|
|
2072
|
-
* Only works for single-line strings
|
|
2073
|
-
*/
|
|
2074
|
-
splitGetRange(separator, text, range) {
|
|
2075
|
-
const chunks = text.split(separator);
|
|
2076
|
-
const result = [];
|
|
2077
|
-
let offset = 0;
|
|
2078
|
-
for (let chunk of chunks) {
|
|
2079
|
-
//only keep nonzero chunks
|
|
2080
|
-
if (chunk.length > 0) {
|
|
2081
|
-
result.push({
|
|
2082
|
-
text: chunk,
|
|
2083
|
-
range: this.createRange(range.start.line, range.start.character + offset, range.end.line, range.start.character + offset + chunk.length)
|
|
2084
|
-
});
|
|
2085
|
-
}
|
|
2086
|
-
offset += chunk.length + separator.length;
|
|
2087
|
-
}
|
|
2088
|
-
return result;
|
|
2089
|
-
}
|
|
2090
1876
|
/**
|
|
2091
1877
|
* Wrap the given code in a markdown code fence (with the language)
|
|
2092
1878
|
*/
|
|
@@ -2158,16 +1944,6 @@ class Util {
|
|
|
2158
1944
|
return result;
|
|
2159
1945
|
/* eslint-enable no-var */
|
|
2160
1946
|
}
|
|
2161
|
-
stringJoin(strings, separator) {
|
|
2162
|
-
var _a;
|
|
2163
|
-
// eslint-disable-next-line no-var
|
|
2164
|
-
var result = (_a = strings[0]) !== null && _a !== void 0 ? _a : '';
|
|
2165
|
-
// eslint-disable-next-line no-var
|
|
2166
|
-
for (var i = 1; i < strings.length; i++) {
|
|
2167
|
-
result += separator + strings[i];
|
|
2168
|
-
}
|
|
2169
|
-
return result;
|
|
2170
|
-
}
|
|
2171
1947
|
/**
|
|
2172
1948
|
* Break an expression into each part.
|
|
2173
1949
|
*/
|
|
@@ -2191,44 +1967,6 @@ class Util {
|
|
|
2191
1967
|
}
|
|
2192
1968
|
return parts;
|
|
2193
1969
|
}
|
|
2194
|
-
/**
|
|
2195
|
-
* Break an expression into each part, and return any VariableExpression or DottedGet expresisons from left-to-right.
|
|
2196
|
-
*/
|
|
2197
|
-
getDottedGetPath(expression) {
|
|
2198
|
-
let parts = [];
|
|
2199
|
-
let nextPart = expression;
|
|
2200
|
-
loop: while (nextPart) {
|
|
2201
|
-
switch (nextPart === null || nextPart === void 0 ? void 0 : nextPart.kind) {
|
|
2202
|
-
case AstNode_1.AstNodeKind.DottedGetExpression:
|
|
2203
|
-
parts.push(nextPart);
|
|
2204
|
-
nextPart = nextPart.obj;
|
|
2205
|
-
continue;
|
|
2206
|
-
case AstNode_1.AstNodeKind.IndexedGetExpression:
|
|
2207
|
-
case AstNode_1.AstNodeKind.XmlAttributeGetExpression:
|
|
2208
|
-
nextPart = nextPart.obj;
|
|
2209
|
-
parts = [];
|
|
2210
|
-
continue;
|
|
2211
|
-
case AstNode_1.AstNodeKind.CallExpression:
|
|
2212
|
-
case AstNode_1.AstNodeKind.CallfuncExpression:
|
|
2213
|
-
nextPart = nextPart.callee;
|
|
2214
|
-
parts = [];
|
|
2215
|
-
continue;
|
|
2216
|
-
case AstNode_1.AstNodeKind.NewExpression:
|
|
2217
|
-
nextPart = nextPart.call.callee;
|
|
2218
|
-
parts = [];
|
|
2219
|
-
continue;
|
|
2220
|
-
case AstNode_1.AstNodeKind.TypeExpression:
|
|
2221
|
-
nextPart = nextPart.expression;
|
|
2222
|
-
continue;
|
|
2223
|
-
case AstNode_1.AstNodeKind.VariableExpression:
|
|
2224
|
-
parts.push(nextPart);
|
|
2225
|
-
break loop;
|
|
2226
|
-
default:
|
|
2227
|
-
return [];
|
|
2228
|
-
}
|
|
2229
|
-
}
|
|
2230
|
-
return parts.reverse();
|
|
2231
|
-
}
|
|
2232
1970
|
/**
|
|
2233
1971
|
* Returns an integer if valid, or undefined. Eliminates checking for NaN
|
|
2234
1972
|
*/
|
|
@@ -2425,6 +2163,19 @@ class Util {
|
|
|
2425
2163
|
crossedCallFunc: crossedCallFunc
|
|
2426
2164
|
};
|
|
2427
2165
|
}
|
|
2166
|
+
getCircularReferenceDiagnosticDetail(circularReferenceInfo, defaultName = '') {
|
|
2167
|
+
if (!circularReferenceInfo || !circularReferenceInfo.referenceChainNames) {
|
|
2168
|
+
if (defaultName) {
|
|
2169
|
+
return [defaultName];
|
|
2170
|
+
}
|
|
2171
|
+
return [];
|
|
2172
|
+
}
|
|
2173
|
+
if (circularReferenceInfo.referenceChainNames[0] === circularReferenceInfo.referenceChainNames[circularReferenceInfo.referenceChainNames.length - 1]) {
|
|
2174
|
+
// last element is same as first it will read okay
|
|
2175
|
+
return circularReferenceInfo.referenceChainNames;
|
|
2176
|
+
}
|
|
2177
|
+
return [...circularReferenceInfo.referenceChainNames, circularReferenceInfo.referenceChainNames[0]];
|
|
2178
|
+
}
|
|
2428
2179
|
isInTypeExpression(expression) {
|
|
2429
2180
|
//TODO: this is much faster than node.findAncestor(), but may need to be updated for "complicated" type expressions
|
|
2430
2181
|
if ((0, reflection_1.isTypeExpression)(expression) ||
|
|
@@ -2543,12 +2294,12 @@ class Util {
|
|
|
2543
2294
|
hasLeadingComments(input) {
|
|
2544
2295
|
var _a;
|
|
2545
2296
|
const leadingTrivia = (0, Token_1.isToken)(input) ? input === null || input === void 0 ? void 0 : input.leadingTrivia : (_a = input === null || input === void 0 ? void 0 : input.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
2546
|
-
return !!leadingTrivia.find(t => t.kind === TokenKind_1.TokenKind.Comment);
|
|
2297
|
+
return !!leadingTrivia.find(t => (t === null || t === void 0 ? void 0 : t.kind) === TokenKind_1.TokenKind.Comment);
|
|
2547
2298
|
}
|
|
2548
2299
|
getLeadingComments(input) {
|
|
2549
2300
|
var _a;
|
|
2550
2301
|
const leadingTrivia = (0, Token_1.isToken)(input) ? input === null || input === void 0 ? void 0 : input.leadingTrivia : (_a = input === null || input === void 0 ? void 0 : input.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
2551
|
-
return leadingTrivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment);
|
|
2302
|
+
return leadingTrivia.filter(t => (t === null || t === void 0 ? void 0 : t.kind) === TokenKind_1.TokenKind.Comment);
|
|
2552
2303
|
}
|
|
2553
2304
|
isLeadingCommentOnSameLine(line, input) {
|
|
2554
2305
|
var _a;
|
|
@@ -2830,6 +2581,17 @@ class Util {
|
|
|
2830
2581
|
}
|
|
2831
2582
|
return resultType;
|
|
2832
2583
|
}
|
|
2584
|
+
/**
|
|
2585
|
+
* Get a short name that can be used to reference the project in logs. (typically something like `prj1`, `prj8`, etc...)
|
|
2586
|
+
*/
|
|
2587
|
+
getProjectLogName(config) {
|
|
2588
|
+
//if we have a project number, use it
|
|
2589
|
+
if ((config === null || config === void 0 ? void 0 : config.projectNumber) !== undefined) {
|
|
2590
|
+
return `prj${config.projectNumber}`;
|
|
2591
|
+
}
|
|
2592
|
+
//just return empty string so log functions don't crash with undefined project numbers
|
|
2593
|
+
return '';
|
|
2594
|
+
}
|
|
2833
2595
|
}
|
|
2834
2596
|
exports.Util = Util;
|
|
2835
2597
|
/**
|
|
@@ -2838,7 +2600,7 @@ exports.Util = Util;
|
|
|
2838
2600
|
*/
|
|
2839
2601
|
function standardizePath(stringParts, ...expressions) {
|
|
2840
2602
|
let result = [];
|
|
2841
|
-
for (let i = 0; i < stringParts.length; i++) {
|
|
2603
|
+
for (let i = 0; i < (stringParts === null || stringParts === void 0 ? void 0 : stringParts.length); i++) {
|
|
2842
2604
|
result.push(stringParts[i], expressions[i]);
|
|
2843
2605
|
}
|
|
2844
2606
|
return exports.util.standardizePath(result.join(''));
|