@platforma-sdk/tengo-builder 1.18.0 → 1.19.1
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/dist/compiler/source.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
- package/src/compiler/source.ts +22 -13
package/src/compiler/source.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import type winston from 'winston';
|
|
3
|
-
import
|
|
4
|
-
TypedArtifactName,
|
|
5
|
-
FullArtifactName,
|
|
6
|
-
ArtifactType,
|
|
7
|
-
CompileMode,
|
|
8
|
-
CompilerOption,
|
|
3
|
+
import {
|
|
4
|
+
type TypedArtifactName,
|
|
5
|
+
type FullArtifactName,
|
|
6
|
+
type ArtifactType,
|
|
7
|
+
type CompileMode,
|
|
8
|
+
type CompilerOption,
|
|
9
|
+
fullNameToString,
|
|
9
10
|
} from './package';
|
|
10
11
|
import type { ArtifactMap } from './artifactset';
|
|
11
12
|
import { createArtifactNameSet } from './artifactset';
|
|
@@ -41,14 +42,15 @@ const newImportAssetRE = (moduleName: string) => {
|
|
|
41
42
|
const emptyLineRE = /^\s*$/;
|
|
42
43
|
const compilerOptionRE = /^\/\/tengo:[\w]/;
|
|
43
44
|
const wrongCompilerOptionRE = /^\s*\/\/\s*tengo:\s*./;
|
|
44
|
-
const
|
|
45
|
+
const inlineCommentRE = /\/\*.*?\*\//g; // .*? = non-greedy search
|
|
46
|
+
const singlelineCommentRE = /^\s*(\/\/)/;
|
|
45
47
|
const multilineCommentStartRE = /^\s*\/\*/;
|
|
46
48
|
const multilineCommentEndRE = /\*\//;
|
|
47
49
|
const importRE = /\s*:=\s*import\s*\(\s*"(?<moduleName>[^"]+)"\s*\)/;
|
|
48
50
|
const importNameRE = new RegExp(
|
|
49
51
|
`\\b(?<importName>${namePattern}(\\.${namePattern})*)${importRE.source}`,
|
|
50
52
|
);
|
|
51
|
-
const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/; // use it to parse <moduleName> from importPattern or <templateName>
|
|
53
|
+
const dependencyRE = /(?<pkgName>[^"]+)?:(?<depID>[^"]+)/; // use it to parse <moduleName> from importPattern or <templateName> from getTemplateID
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Parse compiler option string representation
|
|
@@ -166,7 +168,7 @@ function parseSourceData(
|
|
|
166
168
|
}
|
|
167
169
|
} catch (error: unknown) {
|
|
168
170
|
const err = error as Error;
|
|
169
|
-
throw new Error(`[line ${parserContext.lineNo}]: ${err.message}\n\t${line}
|
|
171
|
+
throw new Error(`[line ${parserContext.lineNo} in ${fullNameToString(fullSourceName)}]: ${err.message}\n\t${line}`, { cause: err });
|
|
170
172
|
}
|
|
171
173
|
}
|
|
172
174
|
|
|
@@ -196,11 +198,14 @@ function parseSingleSourceLine(
|
|
|
196
198
|
artifact: TypedArtifactName | undefined;
|
|
197
199
|
option: CompilerOption | undefined;
|
|
198
200
|
} {
|
|
201
|
+
// preprocess line and remove inline comments
|
|
202
|
+
line = line.replaceAll(inlineCommentRE, '');
|
|
203
|
+
|
|
199
204
|
if (context.isInCommentBlock) {
|
|
200
205
|
if (multilineCommentEndRE.exec(line)) {
|
|
201
206
|
context.isInCommentBlock = false;
|
|
202
207
|
}
|
|
203
|
-
return { line, context, artifact: undefined, option: undefined };
|
|
208
|
+
return { line: '', context, artifact: undefined, option: undefined };
|
|
204
209
|
}
|
|
205
210
|
|
|
206
211
|
if (compilerOptionRE.exec(line)) {
|
|
@@ -220,13 +225,17 @@ function parseSingleSourceLine(
|
|
|
220
225
|
return { line, context, artifact: undefined, option: undefined };
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
if (singlelineCommentRE.
|
|
224
|
-
return { line, context, artifact: undefined, option: undefined };
|
|
228
|
+
if (singlelineCommentRE.test(line)) {
|
|
229
|
+
return { line: '', context, artifact: undefined, option: undefined };
|
|
225
230
|
}
|
|
226
231
|
|
|
227
232
|
if (multilineCommentStartRE.exec(line)) {
|
|
228
233
|
context.isInCommentBlock = true;
|
|
229
|
-
return { line, context, artifact: undefined, option: undefined };
|
|
234
|
+
return { line: '', context, artifact: undefined, option: undefined };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (line.includes('/*')) {
|
|
238
|
+
throw new Error('malformed multiline comment');
|
|
230
239
|
}
|
|
231
240
|
|
|
232
241
|
if (emptyLineRE.exec(line)) {
|