@platforma-sdk/tengo-builder 1.19.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.
@@ -1,11 +1,12 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import type winston from 'winston';
3
- import type {
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 singlelineCommentRE = /^\s*(\/\/)|(\/\*.*\*\/)/;
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> акщь getTemplateID
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,6 +198,9 @@ 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;
@@ -220,7 +225,7 @@ function parseSingleSourceLine(
220
225
  return { line, context, artifact: undefined, option: undefined };
221
226
  }
222
227
 
223
- if (singlelineCommentRE.exec(line)) {
228
+ if (singlelineCommentRE.test(line)) {
224
229
  return { line: '', context, artifact: undefined, option: undefined };
225
230
  }
226
231
 
@@ -229,6 +234,10 @@ function parseSingleSourceLine(
229
234
  return { line: '', context, artifact: undefined, option: undefined };
230
235
  }
231
236
 
237
+ if (line.includes('/*')) {
238
+ throw new Error('malformed multiline comment');
239
+ }
240
+
232
241
  if (emptyLineRE.exec(line)) {
233
242
  return { line, context, artifact: undefined, option: undefined };
234
243
  }