brighterscript 1.0.0-alpha.10 → 1.0.0-alpha.14
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/CHANGELOG.md +247 -267
- package/README.md +2 -2
- package/dist/Cache.d.ts +3 -3
- package/dist/Cache.js +10 -6
- package/dist/Cache.js.map +1 -1
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +4 -4
- package/dist/CommentFlagProcessor.js +5 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticFilterer.js +1 -1
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/LanguageServer.d.ts +1 -6
- package/dist/LanguageServer.js +5 -14
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +3 -3
- package/dist/PluginInterface.js +3 -0
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +35 -20
- package/dist/Program.js +132 -67
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +4 -4
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +22 -13
- package/dist/Scope.js +85 -70
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +1 -1
- package/dist/SymbolTable.js +2 -2
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +2 -2
- package/dist/XmlScope.js +5 -5
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +27 -0
- package/dist/astUtils/AstEditor.js +97 -0
- package/dist/astUtils/AstEditor.js.map +1 -0
- package/dist/{bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts → astUtils/AstEditor.spec.d.ts} +0 -0
- package/dist/astUtils/AstEditor.spec.js +133 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -0
- package/dist/astUtils/creators.spec.js +4 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +4 -2
- package/dist/astUtils/reflection.js +10 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +116 -116
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +13 -13
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.js +1 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +26 -26
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +1 -0
- package/dist/astUtils/xml.js +6 -1
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.js +5 -2
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +3 -3
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +17 -17
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +8 -0
- package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.js → BrsFileSemanticTokensProcessor.js} +13 -15
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.spec.js → BrsFileSemanticTokensProcessor.spec.js} +5 -5
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
- package/dist/diagnosticUtils.d.ts +1 -0
- package/dist/diagnosticUtils.js +14 -7
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +2 -2
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +444 -269
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +17 -11
- package/dist/files/BrsFile.js +220 -153
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +620 -272
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +6 -5
- package/dist/files/XmlFile.js +14 -9
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +238 -191
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +29 -27
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +198 -99
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +71 -10
- package/dist/lexer/Lexer.d.ts +5 -1
- package/dist/lexer/Lexer.js +52 -35
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +564 -534
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +4 -0
- package/dist/lexer/TokenKind.js +44 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/Expression.d.ts +1 -1
- package/dist/parser/Expression.js +66 -66
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +107 -106
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +17 -5
- package/dist/parser/Parser.js +431 -315
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +418 -296
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.js +2 -2
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +22 -22
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +3 -0
- package/dist/parser/SGTypes.js +12 -7
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/SGTypes.spec.js +84 -84
- package/dist/parser/SGTypes.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +3 -3
- package/dist/parser/Statement.js +61 -61
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +10 -10
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +3 -3
- package/dist/parser/tests/Parser.spec.js +4 -4
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +58 -58
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +40 -39
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +201 -200
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +37 -37
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +30 -30
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +119 -119
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +141 -141
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +24 -24
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +41 -40
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +17 -17
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +256 -256
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +87 -87
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +37 -37
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +74 -62
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +41 -41
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +41 -41
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +110 -2
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/Relational.spec.js +43 -43
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +6 -6
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +18 -18
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +100 -100
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +36 -36
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/Declaration.spec.js +44 -44
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +21 -21
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +198 -197
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +15 -14
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +50 -50
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +14 -2
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +17 -17
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +91 -90
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +34 -34
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +46 -46
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +83 -83
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +12 -11
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +5 -5
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +13 -13
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.d.ts +1 -1
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.js +8 -8
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/preprocessor/Preprocessor.spec.js +49 -49
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/types/ArrayType.d.ts +8 -5
- package/dist/types/ArrayType.js +48 -12
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +69 -10
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.js +3 -3
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +2 -2
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -1
- package/dist/types/BscType.js +1 -1
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.d.ts +1 -1
- package/dist/types/CustomType.js +6 -4
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.js +7 -7
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +2 -2
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.js +1 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +2 -2
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/FloatType.js +7 -7
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +2 -2
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +5 -5
- package/dist/types/FunctionType.js +13 -13
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +7 -7
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.js +7 -7
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +2 -2
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.js +3 -3
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +7 -7
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.js +4 -4
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +2 -2
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LazyType.d.ts +1 -2
- package/dist/types/LazyType.js +1 -5
- package/dist/types/LazyType.js.map +1 -1
- package/dist/types/LongIntegerType.js +8 -8
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +2 -2
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.js +3 -3
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +2 -2
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/StringType.js +3 -3
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +2 -2
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/UninitializedType.js +3 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.js +3 -3
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +2 -2
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helpers.js +6 -6
- package/dist/types/helpers.js.map +1 -1
- package/dist/util.d.ts +15 -9
- package/dist/util.js +104 -57
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +40 -40
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +10 -9
- package/dist/astUtils/index.d.ts +0 -7
- package/dist/astUtils/index.js +0 -26
- package/dist/astUtils/index.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +0 -7
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
- package/dist/lexer/index.d.ts +0 -3
- package/dist/lexer/index.js +0 -17
- package/dist/lexer/index.js.map +0 -1
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.js +0 -16
- package/dist/parser/index.js.map +0 -1
- package/dist/preprocessor/index.d.ts +0 -3
- package/dist/preprocessor/index.js +0 -16
- package/dist/preprocessor/index.js.map +0 -1
package/dist/Program.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ import type { BsConfig } from './BsConfig';
|
|
|
4
4
|
import { Scope } from './Scope';
|
|
5
5
|
import { BrsFile } from './files/BrsFile';
|
|
6
6
|
import { XmlFile } from './files/XmlFile';
|
|
7
|
-
import type { BsDiagnostic, FileReference, FileObj, BscFile, SemanticToken } from './interfaces';
|
|
7
|
+
import type { BsDiagnostic, FileReference, FileObj, BscFile, SemanticToken, FileLink } from './interfaces';
|
|
8
8
|
import { XmlScope } from './XmlScope';
|
|
9
9
|
import { Logger } from './Logger';
|
|
10
|
+
import type { ManifestValue } from './preprocessor/Manifest';
|
|
10
11
|
import PluginInterface from './PluginInterface';
|
|
11
12
|
import type { FunctionStatement, Statement } from './parser/Statement';
|
|
13
|
+
import type { SourceMapGenerator } from 'source-map';
|
|
12
14
|
export interface SourceObj {
|
|
13
15
|
srcPath: string;
|
|
14
16
|
source: string;
|
|
@@ -23,10 +25,6 @@ export interface SignatureInfoObj {
|
|
|
23
25
|
key: string;
|
|
24
26
|
signature: SignatureInformation;
|
|
25
27
|
}
|
|
26
|
-
export interface FileLink<T> {
|
|
27
|
-
item: T;
|
|
28
|
-
file: BrsFile;
|
|
29
|
-
}
|
|
30
28
|
export declare class Program {
|
|
31
29
|
/**
|
|
32
30
|
* The root directory for this program
|
|
@@ -77,7 +75,7 @@ export declare class Program {
|
|
|
77
75
|
/**
|
|
78
76
|
* Get a copy of the list of files currently loaded in the program
|
|
79
77
|
*/
|
|
80
|
-
|
|
78
|
+
getAllFiles(): BscFile[];
|
|
81
79
|
private scopes;
|
|
82
80
|
protected addScope(scope: Scope): void;
|
|
83
81
|
/**
|
|
@@ -112,7 +110,7 @@ export declare class Program {
|
|
|
112
110
|
* Get a list of all files that are included in the project but are not referenced
|
|
113
111
|
* by any scope in the program.
|
|
114
112
|
*/
|
|
115
|
-
getUnreferencedFiles():
|
|
113
|
+
getUnreferencedFiles(): BscFile[];
|
|
116
114
|
/**
|
|
117
115
|
* Get the list of errors for the entire program. It's calculated on the fly
|
|
118
116
|
* by walking through every file, so call this sparingly.
|
|
@@ -166,14 +164,14 @@ export declare class Program {
|
|
|
166
164
|
createSourceScope(): void;
|
|
167
165
|
/**
|
|
168
166
|
* Remove a set of files from the program
|
|
169
|
-
* @param
|
|
167
|
+
* @param filePaths can be an array of srcPath or destPath strings
|
|
168
|
+
* @param normalizePath should this function repair and standardize the filePaths? Passing false should have a performance boost if you can guarantee your paths are already sanitized
|
|
170
169
|
*/
|
|
171
|
-
removeFiles(
|
|
170
|
+
removeFiles(filePaths: string[], normalizePath?: boolean): void;
|
|
172
171
|
/**
|
|
173
172
|
* Remove a file from the program
|
|
174
173
|
* @param filePath can be a srcPath, a pkgPath, or a destPath (same as pkgPath but without `pkg:/`)
|
|
175
174
|
* @param normalizePath should this function repair and standardize the path? Passing false should have a performance boost if you can guarantee your path is already sanitized
|
|
176
|
-
|
|
177
175
|
*/
|
|
178
176
|
removeFile(filePath: string, normalizePath?: boolean): void;
|
|
179
177
|
/**
|
|
@@ -195,6 +193,12 @@ export declare class Program {
|
|
|
195
193
|
* Determine at least one scope has the file
|
|
196
194
|
*/
|
|
197
195
|
private fileIsIncludedInAnyScope;
|
|
196
|
+
/**
|
|
197
|
+
* Get the files for a list of filePaths
|
|
198
|
+
* @param filePaths can be an array of srcPath or a destPath strings
|
|
199
|
+
* @param normalizePath should this function repair and standardize the paths? Passing false should have a performance boost if you can guarantee your paths are already sanitized
|
|
200
|
+
*/
|
|
201
|
+
getFiles<T extends BscFile>(filePaths: string[], normalizePath?: boolean): T[];
|
|
198
202
|
/**
|
|
199
203
|
* Get the file at the given path
|
|
200
204
|
* @param filePath can be a srcPath, a pkgPath, or a destPath (same as pkgPath but without `pkg:/`)
|
|
@@ -206,6 +210,10 @@ export declare class Program {
|
|
|
206
210
|
* @param file
|
|
207
211
|
*/
|
|
208
212
|
getScopesForFile(file: XmlFile | BrsFile): Scope[];
|
|
213
|
+
/**
|
|
214
|
+
* Get the first found scope for a file.
|
|
215
|
+
*/
|
|
216
|
+
getFirstScopeForFile(file: XmlFile | BrsFile): Scope;
|
|
209
217
|
getStatementsByName(name: string, originFile: BrsFile, namespaceName?: string): FileLink<Statement>[];
|
|
210
218
|
getStatementsForXmlFile(scope: XmlScope, filterName?: string): FileLink<FunctionStatement>[];
|
|
211
219
|
/**
|
|
@@ -255,25 +263,32 @@ export declare class Program {
|
|
|
255
263
|
* This does not write anything to the file system.
|
|
256
264
|
* @param srcPath The absolute path to the source file on disk
|
|
257
265
|
*/
|
|
258
|
-
getTranspiledFileContents(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
266
|
+
getTranspiledFileContents(pathAbsolute: string): FileTranspileResult;
|
|
267
|
+
/**
|
|
268
|
+
* Internal function used to transpile files.
|
|
269
|
+
* This does not write anything to the file system
|
|
270
|
+
*/
|
|
271
|
+
private _getTranspiledFileContents;
|
|
264
272
|
transpile(fileEntries: FileObj[], stagingFolderPath: string): Promise<void>;
|
|
265
273
|
/**
|
|
266
274
|
* Find a list of files in the program that have a function with the given name (case INsensitive)
|
|
267
275
|
*/
|
|
268
|
-
findFilesForFunction(functionName: string):
|
|
276
|
+
findFilesForFunction(functionName: string): BscFile[];
|
|
269
277
|
/**
|
|
270
|
-
* Find a list of files in the program that have a
|
|
278
|
+
* Find a list of files in the program that have a class with the given name (case INsensitive)
|
|
271
279
|
*/
|
|
272
|
-
findFilesForClass(className: string):
|
|
280
|
+
findFilesForClass(className: string): BscFile[];
|
|
273
281
|
/**
|
|
274
282
|
* Get a map of the manifest information
|
|
275
283
|
*/
|
|
276
|
-
getManifest(): Map<string,
|
|
284
|
+
getManifest(): Map<string, ManifestValue>;
|
|
277
285
|
private _manifest;
|
|
278
286
|
dispose(): void;
|
|
279
287
|
}
|
|
288
|
+
export interface FileTranspileResult {
|
|
289
|
+
srcPath: string;
|
|
290
|
+
pkgPath: string;
|
|
291
|
+
code: string;
|
|
292
|
+
map: SourceMapGenerator;
|
|
293
|
+
typedef: string;
|
|
294
|
+
}
|
package/dist/Program.js
CHANGED
|
@@ -20,10 +20,11 @@ const Manifest_1 = require("./preprocessor/Manifest");
|
|
|
20
20
|
const vscode_uri_1 = require("vscode-uri");
|
|
21
21
|
const PluginInterface_1 = require("./PluginInterface");
|
|
22
22
|
const reflection_1 = require("./astUtils/reflection");
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const Parser_1 = require("./parser/Parser");
|
|
24
|
+
const TokenKind_1 = require("./lexer/TokenKind");
|
|
25
25
|
const BscPlugin_1 = require("./bscPlugin/BscPlugin");
|
|
26
26
|
const roku_deploy_1 = require("roku-deploy");
|
|
27
|
+
const AstEditor_1 = require("./astUtils/AstEditor");
|
|
27
28
|
const bslibNonAliasedRokuModulesPkgPath = `pkg:/source/roku_modules/rokucommunity_bslib/bslib.brs`;
|
|
28
29
|
const bslibAliasedRokuModulesPkgPath = `pkg:/source/roku_modules/bslib/bslib.brs`;
|
|
29
30
|
class Program {
|
|
@@ -112,7 +113,7 @@ class Program {
|
|
|
112
113
|
/**
|
|
113
114
|
* Get a copy of the list of files currently loaded in the program
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
|
+
getAllFiles() {
|
|
116
117
|
return Object.values(this.files);
|
|
117
118
|
}
|
|
118
119
|
addScope(scope) {
|
|
@@ -266,6 +267,7 @@ class Program {
|
|
|
266
267
|
assignFile(file) {
|
|
267
268
|
this.files[file.srcPath.toLowerCase()] = file;
|
|
268
269
|
this.pkgMap[file.pkgPath.toLowerCase()] = file;
|
|
270
|
+
return file;
|
|
269
271
|
}
|
|
270
272
|
/**
|
|
271
273
|
* Remove this file from internal maps
|
|
@@ -273,6 +275,7 @@ class Program {
|
|
|
273
275
|
unassignFile(file) {
|
|
274
276
|
delete this.files[file.srcPath.toLowerCase()];
|
|
275
277
|
delete this.pkgMap[file.pkgPath.toLowerCase()];
|
|
278
|
+
return file;
|
|
276
279
|
}
|
|
277
280
|
setFile(fileParam, fileContents) {
|
|
278
281
|
assert.ok(fileParam, 'fileParam is required');
|
|
@@ -282,7 +285,7 @@ class Program {
|
|
|
282
285
|
//is a pkg path
|
|
283
286
|
if (fileParam.startsWith('pkg:/')) {
|
|
284
287
|
//srcPath is the pkgPath relative to the rootDir
|
|
285
|
-
srcPath = util_1.standardizePath `${this.options.rootDir}/${fileParam.substring(5)}`;
|
|
288
|
+
srcPath = (0, util_1.standardizePath) `${this.options.rootDir}/${fileParam.substring(5)}`;
|
|
286
289
|
pkgPath = fileParam;
|
|
287
290
|
//is a srcPath (absolute path to src file location)
|
|
288
291
|
}
|
|
@@ -293,13 +296,13 @@ class Program {
|
|
|
293
296
|
//is destPath (path relative to rootDir and `pkg:/`)
|
|
294
297
|
}
|
|
295
298
|
else {
|
|
296
|
-
srcPath = util_1.standardizePath `${this.options.rootDir}/${fileParam}`;
|
|
299
|
+
srcPath = (0, util_1.standardizePath) `${this.options.rootDir}/${fileParam}`;
|
|
297
300
|
pkgPath = util_1.util.sanitizePkgPath(fileParam);
|
|
298
301
|
}
|
|
299
302
|
//is a FileObj
|
|
300
303
|
}
|
|
301
304
|
else {
|
|
302
|
-
srcPath = util_1.standardizePath `${fileParam.src}`;
|
|
305
|
+
srcPath = (0, util_1.standardizePath) `${fileParam.src}`;
|
|
303
306
|
pkgPath = util_1.util.sanitizePkgPath(fileParam.dest);
|
|
304
307
|
}
|
|
305
308
|
const lowerPkgPath = pkgPath.toLowerCase();
|
|
@@ -318,7 +321,8 @@ class Program {
|
|
|
318
321
|
source: fileContents
|
|
319
322
|
};
|
|
320
323
|
if (fileExtension === '.brs' || fileExtension === '.bs') {
|
|
321
|
-
|
|
324
|
+
//add the file to the program
|
|
325
|
+
const brsFile = this.assignFile(new BrsFile_1.BrsFile(srcPath, pkgPath, this));
|
|
322
326
|
//add file to the `source` dependency list
|
|
323
327
|
if (brsFile.pkgPath.startsWith('pkg:/source/')) {
|
|
324
328
|
this.createSourceScope();
|
|
@@ -330,35 +334,36 @@ class Program {
|
|
|
330
334
|
this.logger.time(Logger_1.LogLevel.debug, ['parse', chalk_1.default.green(srcPath)], () => {
|
|
331
335
|
brsFile.parse(beforeFileParseEvent.source);
|
|
332
336
|
});
|
|
333
|
-
file
|
|
334
|
-
brsFile.attachDependencyGraph(this.dependencyGraph);
|
|
337
|
+
//notify plugins that this file has finished parsing
|
|
335
338
|
this.plugins.emit('afterFileParse', {
|
|
336
339
|
program: this,
|
|
337
340
|
file: brsFile
|
|
338
341
|
});
|
|
342
|
+
file = brsFile;
|
|
343
|
+
brsFile.attachDependencyGraph(this.dependencyGraph);
|
|
339
344
|
}
|
|
340
345
|
else if (
|
|
341
346
|
//is xml file
|
|
342
347
|
fileExtension === '.xml' &&
|
|
343
348
|
//resides in the components folder (Roku will only parse xml files in the components folder)
|
|
344
349
|
lowerPkgPath.startsWith('pkg:/components/')) {
|
|
345
|
-
let xmlFile = new XmlFile_1.XmlFile(srcPath, pkgPath, this);
|
|
346
|
-
this.assignFile(xmlFile);
|
|
347
350
|
//add the file to the program
|
|
351
|
+
const xmlFile = this.assignFile(new XmlFile_1.XmlFile(srcPath, pkgPath, this));
|
|
348
352
|
this.plugins.emit('beforeFileParse', beforeFileParseEvent);
|
|
349
353
|
this.logger.time(Logger_1.LogLevel.debug, ['parse', chalk_1.default.green(srcPath)], () => {
|
|
350
354
|
xmlFile.parse(beforeFileParseEvent.source);
|
|
351
355
|
});
|
|
356
|
+
//notify plugins that this file has finished parsing
|
|
357
|
+
this.plugins.emit('afterFileParse', {
|
|
358
|
+
program: this,
|
|
359
|
+
file: xmlFile
|
|
360
|
+
});
|
|
352
361
|
file = xmlFile;
|
|
353
362
|
//create a new scope for this xml file
|
|
354
363
|
let scope = new XmlScope_1.XmlScope(xmlFile, this);
|
|
355
364
|
this.addScope(scope);
|
|
356
365
|
//register this compoent now that we have parsed it and know its component name
|
|
357
366
|
this.registerComponent(xmlFile, scope);
|
|
358
|
-
this.plugins.emit('afterFileParse', {
|
|
359
|
-
program: this,
|
|
360
|
-
file: xmlFile
|
|
361
|
-
});
|
|
362
367
|
}
|
|
363
368
|
else {
|
|
364
369
|
//TODO do we actually need to implement this? Figure out how to handle img paths
|
|
@@ -385,18 +390,18 @@ class Program {
|
|
|
385
390
|
}
|
|
386
391
|
/**
|
|
387
392
|
* Remove a set of files from the program
|
|
388
|
-
* @param
|
|
393
|
+
* @param filePaths can be an array of srcPath or destPath strings
|
|
394
|
+
* @param normalizePath should this function repair and standardize the filePaths? Passing false should have a performance boost if you can guarantee your paths are already sanitized
|
|
389
395
|
*/
|
|
390
|
-
removeFiles(
|
|
391
|
-
for (let
|
|
392
|
-
this.removeFile(
|
|
396
|
+
removeFiles(filePaths, normalizePath = true) {
|
|
397
|
+
for (let filiePath of filePaths) {
|
|
398
|
+
this.removeFile(filiePath, normalizePath);
|
|
393
399
|
}
|
|
394
400
|
}
|
|
395
401
|
/**
|
|
396
402
|
* Remove a file from the program
|
|
397
403
|
* @param filePath can be a srcPath, a pkgPath, or a destPath (same as pkgPath but without `pkg:/`)
|
|
398
404
|
* @param normalizePath should this function repair and standardize the path? Passing false should have a performance boost if you can guarantee your path is already sanitized
|
|
399
|
-
|
|
400
405
|
*/
|
|
401
406
|
removeFile(filePath, normalizePath = true) {
|
|
402
407
|
this.logger.debug('Program.removeFile()', filePath);
|
|
@@ -430,7 +435,7 @@ class Program {
|
|
|
430
435
|
this.dependencyGraph.removeDependency('scope:source', file.dependencyGraphKey);
|
|
431
436
|
}
|
|
432
437
|
//if this is a component, remove it from our components map
|
|
433
|
-
if (reflection_1.isXmlFile(file)) {
|
|
438
|
+
if ((0, reflection_1.isXmlFile)(file)) {
|
|
434
439
|
this.unregisterComponent(file);
|
|
435
440
|
}
|
|
436
441
|
this.plugins.emit('afterFileDispose', {
|
|
@@ -483,6 +488,11 @@ class Program {
|
|
|
483
488
|
program: this,
|
|
484
489
|
file: file
|
|
485
490
|
});
|
|
491
|
+
//emit an event to allow plugins to contribute to the file validation process
|
|
492
|
+
this.plugins.emit('onFileValidate', {
|
|
493
|
+
program: this,
|
|
494
|
+
file: file
|
|
495
|
+
});
|
|
486
496
|
//call file.validate() IF the file has that function defined
|
|
487
497
|
(_a = file.validate) === null || _a === void 0 ? void 0 : _a.call(file);
|
|
488
498
|
file.isValidated = true;
|
|
@@ -524,7 +534,7 @@ class Program {
|
|
|
524
534
|
for (const key in this.files) {
|
|
525
535
|
const file = this.files[key];
|
|
526
536
|
//if this is an XmlFile, and it has a valid `componentName` property
|
|
527
|
-
if (reflection_1.isXmlFile(file)) {
|
|
537
|
+
if ((0, reflection_1.isXmlFile)(file)) {
|
|
528
538
|
const componentNameLower = (_a = file.componentName) === null || _a === void 0 ? void 0 : _a.text.toLowerCase();
|
|
529
539
|
if (componentNameLower) {
|
|
530
540
|
if (!componentsByName.has(componentNameLower)) {
|
|
@@ -562,6 +572,16 @@ class Program {
|
|
|
562
572
|
}
|
|
563
573
|
return false;
|
|
564
574
|
}
|
|
575
|
+
/**
|
|
576
|
+
* Get the files for a list of filePaths
|
|
577
|
+
* @param filePaths can be an array of srcPath or a destPath strings
|
|
578
|
+
* @param normalizePath should this function repair and standardize the paths? Passing false should have a performance boost if you can guarantee your paths are already sanitized
|
|
579
|
+
*/
|
|
580
|
+
getFiles(filePaths, normalizePath = true) {
|
|
581
|
+
return filePaths
|
|
582
|
+
.map(filePath => this.getFile(filePath, normalizePath))
|
|
583
|
+
.filter(file => file !== undefined);
|
|
584
|
+
}
|
|
565
585
|
/**
|
|
566
586
|
* Get the file at the given path
|
|
567
587
|
* @param filePath can be a srcPath, a pkgPath, or a destPath (same as pkgPath but without `pkg:/`)
|
|
@@ -592,6 +612,17 @@ class Program {
|
|
|
592
612
|
}
|
|
593
613
|
return result;
|
|
594
614
|
}
|
|
615
|
+
/**
|
|
616
|
+
* Get the first found scope for a file.
|
|
617
|
+
*/
|
|
618
|
+
getFirstScopeForFile(file) {
|
|
619
|
+
for (let key in this.scopes) {
|
|
620
|
+
let scope = this.scopes[key];
|
|
621
|
+
if (scope.hasFile(file)) {
|
|
622
|
+
return scope;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
595
626
|
getStatementsByName(name, originFile, namespaceName) {
|
|
596
627
|
var _a, _b;
|
|
597
628
|
let results = new Map();
|
|
@@ -601,7 +632,7 @@ class Program {
|
|
|
601
632
|
//look through all files in scope for matches
|
|
602
633
|
for (const scope of this.getScopesForFile(originFile)) {
|
|
603
634
|
for (const file of scope.getAllFiles()) {
|
|
604
|
-
if (reflection_1.isXmlFile(file) || filesSearched.has(file)) {
|
|
635
|
+
if ((0, reflection_1.isXmlFile)(file) || filesSearched.has(file)) {
|
|
605
636
|
continue;
|
|
606
637
|
}
|
|
607
638
|
filesSearched.add(file);
|
|
@@ -624,9 +655,9 @@ class Program {
|
|
|
624
655
|
//get all function names for the xml file and parents
|
|
625
656
|
let funcNames = new Set();
|
|
626
657
|
let currentScope = scope;
|
|
627
|
-
while (reflection_1.isXmlScope(currentScope)) {
|
|
658
|
+
while ((0, reflection_1.isXmlScope)(currentScope)) {
|
|
628
659
|
for (let member of (_b = (_a = currentScope.xmlFile.ast.component) === null || _a === void 0 ? void 0 : _a.interfaceMembers) !== null && _b !== void 0 ? _b : []) {
|
|
629
|
-
if (reflection_1.isSGInterfaceFunction(member)) {
|
|
660
|
+
if ((0, reflection_1.isSGInterfaceFunction)(member)) {
|
|
630
661
|
const name = member.name;
|
|
631
662
|
if (!filterName || name === filterName) {
|
|
632
663
|
funcNames.add(name);
|
|
@@ -637,7 +668,7 @@ class Program {
|
|
|
637
668
|
}
|
|
638
669
|
//look through all files in scope for matches
|
|
639
670
|
for (const file of scope.getOwnFiles()) {
|
|
640
|
-
if (reflection_1.isXmlFile(file) || filesSearched.has(file)) {
|
|
671
|
+
if ((0, reflection_1.isXmlFile)(file) || filesSearched.has(file)) {
|
|
641
672
|
continue;
|
|
642
673
|
}
|
|
643
674
|
filesSearched.add(file);
|
|
@@ -663,9 +694,9 @@ class Program {
|
|
|
663
694
|
return [];
|
|
664
695
|
}
|
|
665
696
|
let result = [];
|
|
666
|
-
if (reflection_1.isBrsFile(file) && file.parser.isPositionNextToTokenKind(position,
|
|
697
|
+
if ((0, reflection_1.isBrsFile)(file) && file.parser.isPositionNextToTokenKind(position, TokenKind_1.TokenKind.Callfunc)) {
|
|
667
698
|
// is next to a @. callfunc invocation - must be an interface method
|
|
668
|
-
for (const scope of this.getScopes().filter((s) => reflection_1.isXmlScope(s))) {
|
|
699
|
+
for (const scope of this.getScopes().filter((s) => (0, reflection_1.isXmlScope)(s))) {
|
|
669
700
|
let fileLinks = this.getStatementsForXmlFile(scope);
|
|
670
701
|
for (let fileLink of fileLinks) {
|
|
671
702
|
result.push(scope.createCompletionFromFunctionStatement(fileLink.item));
|
|
@@ -703,7 +734,7 @@ class Program {
|
|
|
703
734
|
const result = [];
|
|
704
735
|
for (const key in this.files) {
|
|
705
736
|
const file = this.files[key];
|
|
706
|
-
if (reflection_1.isBrsFile(file)) {
|
|
737
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
707
738
|
result.push(...file.getWorkspaceSymbols());
|
|
708
739
|
}
|
|
709
740
|
}
|
|
@@ -719,7 +750,7 @@ class Program {
|
|
|
719
750
|
if (!file) {
|
|
720
751
|
return [];
|
|
721
752
|
}
|
|
722
|
-
if (reflection_1.isBrsFile(file)) {
|
|
753
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
723
754
|
return file.getDefinition(position);
|
|
724
755
|
}
|
|
725
756
|
else {
|
|
@@ -740,7 +771,8 @@ class Program {
|
|
|
740
771
|
if (!file) {
|
|
741
772
|
return null;
|
|
742
773
|
}
|
|
743
|
-
|
|
774
|
+
const hover = file.getHover(position);
|
|
775
|
+
return Promise.resolve(hover);
|
|
744
776
|
}
|
|
745
777
|
/**
|
|
746
778
|
* Compute code actions for the given file and range
|
|
@@ -788,7 +820,7 @@ class Program {
|
|
|
788
820
|
getSignatureHelp(filepath, position) {
|
|
789
821
|
var _a;
|
|
790
822
|
let file = this.getFile(filepath);
|
|
791
|
-
if (!file || !reflection_1.isBrsFile(file)) {
|
|
823
|
+
if (!file || !(0, reflection_1.isBrsFile)(file)) {
|
|
792
824
|
return [];
|
|
793
825
|
}
|
|
794
826
|
const results = new Map();
|
|
@@ -816,9 +848,9 @@ class Program {
|
|
|
816
848
|
scope.linkSymbolTable();
|
|
817
849
|
let myClass = file.getClassFromToken(currentToken, functionExpression, scope);
|
|
818
850
|
if (myClass) {
|
|
819
|
-
let classes = scope.getClassHierarchy(myClass.item.getName(
|
|
851
|
+
let classes = scope.getClassHierarchy(myClass.item.getName(Parser_1.ParseMode.BrighterScript).toLowerCase());
|
|
820
852
|
//and anything from any class in scope to a non m class
|
|
821
|
-
for (let statement of [...classes].filter((i) => reflection_1.isClassMethodStatement(i.item))) {
|
|
853
|
+
for (let statement of [...classes].filter((i) => (0, reflection_1.isClassMethodStatement)(i.item))) {
|
|
822
854
|
let sigHelp = statement.file.getSignatureHelpForStatement(statement.item);
|
|
823
855
|
if (sigHelp && !results.has[sigHelp.key]) {
|
|
824
856
|
results.set(sigHelp.key, sigHelp);
|
|
@@ -848,7 +880,7 @@ class Program {
|
|
|
848
880
|
}
|
|
849
881
|
}
|
|
850
882
|
else if (identifierInfo.statementType === '@.') {
|
|
851
|
-
for (const scope of this.getScopes().filter((s) => reflection_1.isXmlScope(s))) {
|
|
883
|
+
for (const scope of this.getScopes().filter((s) => (0, reflection_1.isXmlScope)(s))) {
|
|
852
884
|
let fileLinks = this.getStatementsForXmlFile(scope, identifierInfo.name);
|
|
853
885
|
for (let fileLink of fileLinks) {
|
|
854
886
|
let sigHelp = fileLink.file.getSignatureHelpForStatement(fileLink.item);
|
|
@@ -888,12 +920,12 @@ class Program {
|
|
|
888
920
|
//try to get sig help based on the name
|
|
889
921
|
index = position.character;
|
|
890
922
|
let currentToken = file.parser.getTokenAt(position);
|
|
891
|
-
if (currentToken && currentToken.kind !==
|
|
892
|
-
name = file.getPartialVariableName(currentToken, [
|
|
923
|
+
if (currentToken && currentToken.kind !== TokenKind_1.TokenKind.Comment) {
|
|
924
|
+
name = file.getPartialVariableName(currentToken, [TokenKind_1.TokenKind.New]);
|
|
893
925
|
if (!name) {
|
|
894
926
|
//try the previous token, incase we're on a bracket
|
|
895
927
|
currentToken = file.parser.getPreviousToken(currentToken);
|
|
896
|
-
name = file.getPartialVariableName(currentToken, [
|
|
928
|
+
name = file.getPartialVariableName(currentToken, [TokenKind_1.TokenKind.New]);
|
|
897
929
|
}
|
|
898
930
|
if (name === null || name === void 0 ? void 0 : name.indexOf('.')) {
|
|
899
931
|
let parts = name.split('.');
|
|
@@ -1063,21 +1095,63 @@ class Program {
|
|
|
1063
1095
|
* This does not write anything to the file system.
|
|
1064
1096
|
* @param srcPath The absolute path to the source file on disk
|
|
1065
1097
|
*/
|
|
1066
|
-
getTranspiledFileContents(
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1098
|
+
getTranspiledFileContents(pathAbsolute) {
|
|
1099
|
+
return this._getTranspiledFileContents(this.getFile(pathAbsolute));
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Internal function used to transpile files.
|
|
1103
|
+
* This does not write anything to the file system
|
|
1104
|
+
*/
|
|
1105
|
+
_getTranspiledFileContents(file, outputPath) {
|
|
1106
|
+
const editor = new AstEditor_1.AstEditor();
|
|
1107
|
+
this.plugins.emit('beforeFileTranspile', {
|
|
1108
|
+
file: file,
|
|
1109
|
+
program: this,
|
|
1110
|
+
outputPath: outputPath,
|
|
1111
|
+
editor: editor
|
|
1112
|
+
});
|
|
1113
|
+
//if we have any edits, assume the file needs to be transpiled
|
|
1114
|
+
if (editor.hasChanges) {
|
|
1115
|
+
//use the `editor` because it'll track the previous value for us and revert later on
|
|
1116
|
+
editor.setProperty(file, 'needsTranspiled', true);
|
|
1117
|
+
}
|
|
1118
|
+
//transpile the file
|
|
1119
|
+
const result = file.transpile();
|
|
1120
|
+
//generate the typedef if enabled
|
|
1121
|
+
let typedef;
|
|
1122
|
+
if ((0, reflection_1.isBrsFile)(file) && this.options.emitDefinitions) {
|
|
1123
|
+
typedef = file.getTypedef();
|
|
1124
|
+
}
|
|
1125
|
+
const event = {
|
|
1126
|
+
file: file,
|
|
1127
|
+
program: this,
|
|
1128
|
+
outputPath: outputPath,
|
|
1129
|
+
editor: editor,
|
|
1130
|
+
code: result.code,
|
|
1131
|
+
map: result.map,
|
|
1132
|
+
typedef: typedef
|
|
1133
|
+
};
|
|
1134
|
+
this.plugins.emit('afterFileTranspile', event);
|
|
1135
|
+
//undo all `editor` edits that may have been applied to this file.
|
|
1136
|
+
editor.undoAll();
|
|
1137
|
+
return {
|
|
1138
|
+
srcPath: file.srcPath,
|
|
1139
|
+
pkgPath: file.pkgPath,
|
|
1140
|
+
code: event.code,
|
|
1141
|
+
map: event.map,
|
|
1142
|
+
typedef: event.typedef
|
|
1143
|
+
};
|
|
1070
1144
|
}
|
|
1071
1145
|
async transpile(fileEntries, stagingFolderPath) {
|
|
1072
1146
|
// map fileEntries using their path as key to avoid excessive "find()" operations
|
|
1073
1147
|
const mappedFileEntries = fileEntries.reduce((collection, entry) => {
|
|
1074
|
-
collection[util_1.standardizePath `${entry.src}`] = entry;
|
|
1148
|
+
collection[(0, util_1.standardizePath) `${entry.src}`] = entry;
|
|
1075
1149
|
return collection;
|
|
1076
1150
|
}, {});
|
|
1077
1151
|
const entries = [];
|
|
1078
1152
|
for (const key in this.files) {
|
|
1079
1153
|
const file = this.files[key];
|
|
1080
|
-
let filePathObj = mappedFileEntries[util_1.standardizePath `${file.srcPath}`];
|
|
1154
|
+
let filePathObj = mappedFileEntries[(0, util_1.standardizePath) `${file.srcPath}`];
|
|
1081
1155
|
if (!filePathObj) {
|
|
1082
1156
|
//this file has been added in-memory, from a plugin, for example
|
|
1083
1157
|
filePathObj = {
|
|
@@ -1093,10 +1167,12 @@ class Program {
|
|
|
1093
1167
|
//change any .bs file extension to .brs
|
|
1094
1168
|
.replace(/\.bs$/gi, '.brs');
|
|
1095
1169
|
//prepend the staging folder path
|
|
1096
|
-
outputPath = util_1.standardizePath `${stagingFolderPath}/${outputPath}`;
|
|
1170
|
+
outputPath = (0, util_1.standardizePath) `${stagingFolderPath}/${outputPath}`;
|
|
1097
1171
|
entries.push({
|
|
1098
1172
|
file: file,
|
|
1099
|
-
|
|
1173
|
+
program: this,
|
|
1174
|
+
outputPath: outputPath,
|
|
1175
|
+
editor: new AstEditor_1.AstEditor()
|
|
1100
1176
|
});
|
|
1101
1177
|
}
|
|
1102
1178
|
this.plugins.emit('beforeProgramTranspile', {
|
|
@@ -1105,36 +1181,25 @@ class Program {
|
|
|
1105
1181
|
});
|
|
1106
1182
|
const promises = entries.map(async (entry) => {
|
|
1107
1183
|
//skip transpiling typedef files
|
|
1108
|
-
if (reflection_1.isBrsFile(entry.file) && entry.file.isTypedef) {
|
|
1184
|
+
if ((0, reflection_1.isBrsFile)(entry.file) && entry.file.isTypedef) {
|
|
1109
1185
|
return;
|
|
1110
1186
|
}
|
|
1111
|
-
this.plugins.emit('beforeFileTranspile', {
|
|
1112
|
-
program: this,
|
|
1113
|
-
file: entry.file,
|
|
1114
|
-
outputPath: entry.outputPath
|
|
1115
|
-
});
|
|
1116
1187
|
const { file, outputPath } = entry;
|
|
1117
|
-
const
|
|
1188
|
+
const fileTranspileResult = this._getTranspiledFileContents(file, outputPath);
|
|
1118
1189
|
//make sure the full dir path exists
|
|
1119
1190
|
await fsExtra.ensureDir(path.dirname(outputPath));
|
|
1120
1191
|
if (await fsExtra.pathExists(outputPath)) {
|
|
1121
1192
|
throw new Error(`Error while transpiling "${file.srcPath}". A file already exists at "${outputPath}" and will not be overwritten.`);
|
|
1122
1193
|
}
|
|
1123
|
-
const writeMapPromise =
|
|
1194
|
+
const writeMapPromise = fileTranspileResult.map ? fsExtra.writeFile(`${outputPath}.map`, fileTranspileResult.map.toString()) : null;
|
|
1124
1195
|
await Promise.all([
|
|
1125
|
-
fsExtra.writeFile(outputPath,
|
|
1196
|
+
fsExtra.writeFile(outputPath, fileTranspileResult.code),
|
|
1126
1197
|
writeMapPromise
|
|
1127
1198
|
]);
|
|
1128
|
-
if (
|
|
1129
|
-
const typedef = file.getTypedef();
|
|
1199
|
+
if (fileTranspileResult.typedef) {
|
|
1130
1200
|
const typedefPath = outputPath.replace(/\.brs$/i, '.d.bs');
|
|
1131
|
-
await fsExtra.writeFile(typedefPath, typedef);
|
|
1201
|
+
await fsExtra.writeFile(typedefPath, fileTranspileResult.typedef);
|
|
1132
1202
|
}
|
|
1133
|
-
this.plugins.emit('afterFileTranspile', {
|
|
1134
|
-
program: this,
|
|
1135
|
-
file: entry.file,
|
|
1136
|
-
outputPath: entry.outputPath
|
|
1137
|
-
});
|
|
1138
1203
|
});
|
|
1139
1204
|
//if there's no bslib file already loaded into the program, copy it to the staging directory
|
|
1140
1205
|
if (!this.getFile(bslibAliasedRokuModulesPkgPath) && !this.getFile(`pkg:/source/bslib.brs`)) {
|
|
@@ -1154,7 +1219,7 @@ class Program {
|
|
|
1154
1219
|
const lowerFunctionName = functionName.toLowerCase();
|
|
1155
1220
|
//find every file with this function defined
|
|
1156
1221
|
for (const file of Object.values(this.files)) {
|
|
1157
|
-
if (reflection_1.isBrsFile(file)) {
|
|
1222
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
1158
1223
|
//TODO handle namespace-relative function calls
|
|
1159
1224
|
//if the file has a function with this name
|
|
1160
1225
|
if (file.parser.references.functionStatementLookup.get(lowerFunctionName) !== undefined) {
|
|
@@ -1165,14 +1230,14 @@ class Program {
|
|
|
1165
1230
|
return files;
|
|
1166
1231
|
}
|
|
1167
1232
|
/**
|
|
1168
|
-
* Find a list of files in the program that have a
|
|
1233
|
+
* Find a list of files in the program that have a class with the given name (case INsensitive)
|
|
1169
1234
|
*/
|
|
1170
1235
|
findFilesForClass(className) {
|
|
1171
1236
|
const files = [];
|
|
1172
1237
|
const lowerClassName = className.toLowerCase();
|
|
1173
1238
|
//find every file with this class defined
|
|
1174
1239
|
for (const file of Object.values(this.files)) {
|
|
1175
|
-
if (reflection_1.isBrsFile(file)) {
|
|
1240
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
1176
1241
|
//TODO handle namespace-relative classes
|
|
1177
1242
|
//if the file has a function with this name
|
|
1178
1243
|
if (file.parser.references.classStatementLookup.get(lowerClassName) !== undefined) {
|
|
@@ -1194,7 +1259,7 @@ class Program {
|
|
|
1194
1259
|
try {
|
|
1195
1260
|
//we only load this manifest once, so do it sync to improve speed downstream
|
|
1196
1261
|
contents = fsExtra.readFileSync(manifestPath, 'utf-8');
|
|
1197
|
-
this._manifest = Manifest_1.parseManifest(contents);
|
|
1262
|
+
this._manifest = (0, Manifest_1.parseManifest)(contents);
|
|
1198
1263
|
}
|
|
1199
1264
|
catch (err) {
|
|
1200
1265
|
this._manifest = new Map();
|