squiffy-compiler 6.0.0 → 7.0.0-beta.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.js CHANGED
@@ -1,690 +1,28 @@
1
- import pkg from "../package.json" with { type: "json" };
2
- import { findV5Syntax } from "./v5.js";
3
- const version = pkg.version;
1
+ import { analyse, analysisInternals } from "./analyse.js";
2
+ import { emit } from "./emit.js";
4
3
  export { findV5Syntax, convertV5Syntax } from "./v5.js";
4
+ // The compiler works in three stages, which can also be used separately:
5
+ // - parse() turns one file into a syntax tree, with a source range on every node
6
+ // - analyse() resolves @imports, builds the story's sections and passages, and reports diagnostics
7
+ // - emit() turns a successful analysis into the story data and JavaScript the runtime needs
8
+ export { parse } from "./parse.js";
9
+ export { analyse, ParseCache } from "./analyse.js";
10
+ export { emit } from "./emit.js";
11
+ export { formatDiagnostic } from "./syntax.js";
5
12
  export async function compile(settings) {
6
- const story = new Story();
7
- const errors = [];
8
- let autoSectionCount = 0;
9
- async function getJs(storyData, excludeHeader) {
10
- const outputJs = [];
11
- if (!excludeHeader) {
12
- outputJs.push(`// Created with Squiffy ${version}`);
13
- outputJs.push("// https://github.com/textadventures/squiffy");
14
- }
15
- if (settings.globalJs) {
16
- outputJs.push("var story = {};");
17
- }
18
- else {
19
- outputJs.push("export const story = {};");
20
- }
21
- outputJs.push(`story.id = ${JSON.stringify(storyData.story.id, null, 4)};`);
22
- if (storyData.story.uiJsIndex !== undefined) {
23
- outputJs.push(`story.uiJsIndex = ${storyData.story.uiJsIndex};`);
24
- }
25
- outputJs.push(`story.start = ${JSON.stringify(storyData.story.start, null, 4)};`);
26
- outputJs.push(`story.sections = ${JSON.stringify(storyData.story.sections, null, 4)};`);
27
- outputJs.push("story.js = [");
28
- for (const js of storyData.js) {
29
- writeJs(outputJs, 1, js);
30
- }
31
- outputJs.push("];");
32
- return outputJs.join("\n");
33
- }
34
- async function getStoryData() {
35
- if (!story.start) {
36
- story.start = Object.keys(story.sections)[0];
37
- }
38
- const output = {
39
- story: {
40
- start: story.start,
41
- id: story.id,
42
- sections: {},
43
- },
44
- js: [],
45
- };
46
- if (story.uiJs.length > 0) {
47
- output.js.push(story.uiJs);
48
- output.story.uiJsIndex = output.js.length - 1;
49
- }
50
- for (const sectionName of Object.keys(story.sections)) {
51
- const section = story.sections[sectionName];
52
- const outputSection = {};
53
- output.story.sections[sectionName] = outputSection;
54
- if (section.clear) {
55
- outputSection.clear = true;
56
- }
57
- outputSection.text = await processText(section.text.join("\n"), section, null);
58
- if (section.attributes.length > 0) {
59
- outputSection.attributes = section.attributes;
60
- }
61
- if (section.js.length > 0) {
62
- output.js.push(section.js);
63
- outputSection.jsIndex = output.js.length - 1;
64
- }
65
- if ("@last" in section.passages) {
66
- let passageCount = 0;
67
- for (const passageName of Object.keys(section.passages)) {
68
- if (passageName.length > 0 && passageName?.substring(0, 1) !== "@") {
69
- passageCount++;
70
- }
71
- }
72
- outputSection.passageCount = passageCount;
73
- }
74
- if (Object.keys(section.passages).length == 0)
75
- continue;
76
- outputSection.passages = {};
77
- for (const passageName of Object.keys(section.passages)) {
78
- const passage = section.passages[passageName];
79
- const outputPassage = {};
80
- outputSection.passages[passageName] = outputPassage;
81
- if (passage.clear) {
82
- outputPassage.clear = true;
83
- }
84
- outputPassage.text = await processText(passage.text.join("\n"), section, passage);
85
- if (passage.attributes.length > 0) {
86
- outputPassage.attributes = passage.attributes;
87
- }
88
- if (passage.js.length > 0) {
89
- output.js.push(passage.js);
90
- outputPassage.jsIndex = output.js.length - 1;
91
- }
92
- }
93
- }
94
- return output;
95
- }
96
- const regexes = {
97
- section: /^\[\[(.*)\]\]:$/,
98
- snippet: /^\[snippet:\s*(.+)\]:$/,
99
- passage: /^\[(.*)\]:$/,
100
- title: /^@title (.*)$/,
101
- import: /^@import (.*)$/,
102
- start: /^@start (.*)$/,
103
- attributes: /^@set (.*)$/,
104
- unset: /^@unset (.*)$/,
105
- inc: /^@inc (\S+)(?: (\d+))?$/,
106
- dec: /^@dec (\S+)(?: (\d+))?$/,
107
- js: /^(\t| {4})(.*)$/,
108
- continue: /^\+\+\+(.*)$/,
109
- ui: /^@ui (.*)$/,
110
- };
111
- async function processFileText(inputText, inputFilename, isFirst) {
112
- warnAboutV5Syntax(inputText, inputFilename);
113
- const inputLines = inputText.replace(/\r/g, "").split("\n");
114
- let lineCount = 0;
115
- let section = null;
116
- let passage = null; // annotated differently to section, as a workaround for TypeScript "Property does not exist on type never"
117
- let textStarted = false;
118
- let inUiBlock = false;
119
- let inSnippet = false;
120
- const ensureThisSectionExists = () => {
121
- return ensureSectionExists(section, isFirst, inputFilename, lineCount);
122
- };
123
- const addAutoSection = () => {
124
- autoSectionCount++;
125
- const autoSectionName = `_continue${autoSectionCount}`;
126
- section = story.addSection(autoSectionName, inputFilename, lineCount);
127
- passage = null;
128
- textStarted = false;
129
- return autoSectionName;
130
- };
131
- for (const line of inputLines) {
132
- const stripLine = line.trim();
133
- lineCount++;
134
- const match = {};
135
- for (const key of Object.keys(regexes)) {
136
- const regex = regexes[key];
137
- const result = key == "js" ? regex.exec(line) : regex.exec(stripLine);
138
- if (result) {
139
- match[key] = result;
140
- }
141
- }
142
- if (match.snippet) {
143
- inSnippet = true;
144
- section = null;
145
- passage = null;
146
- textStarted = false;
147
- }
148
- else if (match.section) {
149
- inSnippet = false;
150
- section = story.addSection(match.section[1], inputFilename, lineCount);
151
- passage = null;
152
- textStarted = false;
153
- }
154
- else if (inSnippet) {
155
- // skip all content inside snippet blocks
156
- }
157
- else if (match.passage) {
158
- if (!section) {
159
- errors.push(`ERROR: ${inputFilename} line ${lineCount}: Can't add passage "${match.passage[1]}" as no section has been created.`);
160
- return false;
161
- }
162
- section = ensureThisSectionExists();
163
- passage = section.addPassage(match.passage[1], lineCount);
164
- textStarted = false;
165
- }
166
- else if (match.continue) {
167
- section = ensureThisSectionExists();
168
- const previousSection = section;
169
- const autoSectionName = addAutoSection();
170
- const text = match.continue[1] || "Continue...";
171
- previousSection.addText(`[[${text}]](${autoSectionName})`);
172
- }
173
- else if (stripLine == "---") {
174
- inUiBlock = false;
175
- if (!section) {
176
- // Just add the _default section if we haven't started yet
177
- ensureThisSectionExists();
178
- }
179
- else {
180
- addAutoSection();
181
- }
182
- }
183
- else if (stripLine == "@ui") {
184
- inUiBlock = true;
185
- }
186
- else if (match.ui && settings.externalFiles) {
187
- const content = await settings.externalFiles.getContent(match.ui[1]);
188
- story.addUiJs(content);
189
- }
190
- else if (stripLine == "@clear") {
191
- if (!passage) {
192
- section = ensureThisSectionExists();
193
- section.clear = true;
194
- }
195
- else {
196
- passage.clear = true;
197
- }
198
- }
199
- else if (match.title) {
200
- story.title = match.title[1];
201
- }
202
- else if (match.start) {
203
- story.start = match.start[1];
204
- }
205
- else if (match.import && settings.externalFiles) {
206
- const importFilenames = await settings.externalFiles.getMatchingFilenames(match.import[1]);
207
- for (const importFilename of importFilenames) {
208
- if (importFilename.endsWith(".squiffy")) {
209
- const content = await settings.externalFiles.getContent(importFilename);
210
- const success = await processFileText(content, importFilename, false);
211
- if (!success)
212
- return false;
213
- }
214
- else if (importFilename.endsWith(".js")) {
215
- story.scripts.push(settings.externalFiles.getLocalFilename(importFilename));
216
- }
217
- else if (importFilename.endsWith(".css")) {
218
- story.stylesheets.push(settings.externalFiles.getLocalFilename(importFilename));
219
- }
220
- }
221
- }
222
- else if (match.attributes) {
223
- section = ensureThisSectionExists();
224
- section = addAttribute(match.attributes[1], section, passage, isFirst, inputFilename, lineCount);
225
- }
226
- else if (match.unset) {
227
- section = ensureThisSectionExists();
228
- section = addAttribute("not " + match.unset[1], section, passage, isFirst, inputFilename, lineCount);
229
- }
230
- else if (match.inc) {
231
- section = ensureThisSectionExists();
232
- section = addAttribute(match.inc[1] + "+=" + (match.inc[2] === undefined ? "1" : match.inc[2]), section, passage, isFirst, inputFilename, lineCount);
233
- }
234
- else if (match.dec) {
235
- section = ensureThisSectionExists();
236
- section = addAttribute(match.dec[1] + "-=" + (match.dec[2] === undefined ? "1" : match.dec[2]), section, passage, isFirst, inputFilename, lineCount);
237
- }
238
- else if (!textStarted && match.js) {
239
- if (inUiBlock) {
240
- story.addUiJs(match.js[2]);
241
- }
242
- else if (!passage) {
243
- section = ensureThisSectionExists();
244
- section.addJS(match.js[2]);
245
- }
246
- else {
247
- passage.addJS(match.js[2]);
248
- }
249
- }
250
- else if (textStarted || stripLine.length > 0) {
251
- if (inUiBlock) {
252
- errors.push(`ERROR: ${inputFilename} line ${lineCount}: Unexpected text in @ui block.`);
253
- return false;
254
- }
255
- else if (!passage) {
256
- section = ensureThisSectionExists();
257
- if (section) {
258
- section.addText(line);
259
- textStarted = true;
260
- }
261
- }
262
- else {
263
- passage.addText(line);
264
- textStarted = true;
265
- }
266
- }
267
- }
268
- return true;
269
- }
270
- function warnAboutV5Syntax(inputText, inputFilename) {
271
- if (!settings.onWarning)
272
- return;
273
- const truncate = (s) => s.length > 60 ? s.substring(0, 57) + "..." : s;
274
- for (const match of findV5Syntax(inputText)) {
275
- let warning = `WARNING: ${inputFilename} line ${match.line}: ${truncate(match.text)} looks like Squiffy 5 text processor syntax, which isn't supported in Squiffy 6.`;
276
- if (match.suggestion) {
277
- warning += match.suggestion.length > 60
278
- ? " Convert it to Handlebars syntax."
279
- : ` Use ${match.suggestion} instead.`;
280
- }
281
- else if (match.text.startsWith("{else:")) {
282
- warning += " Use {{else}} inside an {{#if}} block instead.";
283
- }
13
+ const analysis = await analyse(settings);
14
+ const { legacyErrors, legacyWarnings } = analysisInternals.get(analysis);
15
+ if (settings.onWarning) {
16
+ for (const warning of legacyWarnings) {
284
17
  settings.onWarning(warning);
285
18
  }
286
19
  }
287
- function ensureSectionExists(section, isFirst, inputFilename, lineCount) {
288
- if (!section && isFirst) {
289
- section = story.addSection("_default", inputFilename, lineCount);
290
- }
291
- return section;
292
- }
293
- function addAttribute(attribute, section, passage, isFirst, inputFilename, lineCount) {
294
- if (!passage) {
295
- section = ensureSectionExists(section, isFirst, inputFilename, lineCount);
296
- section.addAttribute(attribute);
297
- }
298
- else {
299
- passage.addAttribute(attribute);
300
- }
301
- return section;
302
- }
303
- function extractLinkFunctions(link) {
304
- const fragments = link.split(",");
305
- return {
306
- target: fragments[0].trim(),
307
- setters: fragments.slice(1).join(", ")
308
- };
309
- }
310
- function getAdditionalLinkParameters(link) {
311
- const functions = extractLinkFunctions(link);
312
- let additionalParameters = "";
313
- if (functions.setters.length > 0) {
314
- additionalParameters += ` set="${functions.setters}"`;
315
- }
316
- return {
317
- target: functions.target,
318
- additionalParameters
319
- };
320
- }
321
- function escapeForHandlebarsString(s) {
322
- return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
323
- }
324
- async function processText(input, section, passage) {
325
- // Helper to get the next section name
326
- const getNextSectionName = () => {
327
- const sectionNames = Object.keys(story.sections);
328
- const currentIndex = sectionNames.indexOf(section.name);
329
- return sectionNames[currentIndex + 1] || null;
330
- };
331
- // Handlebars expressions can contain square brackets that aren't links, such as
332
- // {{someArray.[1]}} or {{someHelper "[x]"}}, so swap each one for a placeholder while
333
- // converting links. Text between block helpers like {{#if x}}...{{/if}} is still converted.
334
- const mustaches = [];
335
- input = input.replace(/\{\{\{[\s\S]*?\}\}\}|\{\{[\s\S]*?\}\}/g, match => {
336
- mustaches.push(match);
337
- return `\uE000${mustaches.length - 1}\uE001`;
338
- });
339
- const restore = (s) => s.replace(/\uE000(\d+)\uE001/g, (_match, i) => mustaches[Number(i)]);
340
- // nextSectionLinkRegex matches [[text>]] - a link to the next section
341
- const nextSectionLinkRegex = /\[\[([^\]]*?)>\]\]/g;
342
- input = input.replace(nextSectionLinkRegex, (_match, text) => {
343
- text = restore(text);
344
- const nextSectionName = getNextSectionName();
345
- if (!nextSectionName) {
346
- settings.onWarning?.(`WARNING: ${section.filename} line ${section.line}: In section '${section.name}', there is a [[${text}>]] link but no following section exists`);
347
- return `[[${text}]]`; // fallback
348
- }
349
- return `{{section "${escapeForHandlebarsString(nextSectionName)}" text="${escapeForHandlebarsString(text)}"}}`;
350
- });
351
- // namedNextSectionLinkRegex matches [[text]](>) or [[text]](>, setter=value)
352
- // - a named link where target starts with >
353
- const namedNextSectionLinkRegex = /\[\[([^\]]*?)\]\]\(>(.*?)\)/g;
354
- input = input.replace(namedNextSectionLinkRegex, (_match, text, rest) => {
355
- text = restore(text);
356
- rest = restore(rest);
357
- const nextSectionName = getNextSectionName();
358
- if (!nextSectionName) {
359
- settings.onWarning?.(`WARNING: ${section.filename} line ${section.line}: In section '${section.name}', there is a [[${text}]](>) link but no following section exists`);
360
- return `[[${text}]]`; // fallback
361
- }
362
- // rest could be empty or ", setter=value"
363
- const parsedName = getAdditionalLinkParameters(nextSectionName + rest);
364
- return `{{section "${escapeForHandlebarsString(parsedName.target)}" text="${escapeForHandlebarsString(text)}"${parsedName.additionalParameters}}}`;
365
- });
366
- // namedSectionLinkRegex matches:
367
- // open [[
368
- // any text - the link text
369
- // closing ]]
370
- // open bracket
371
- // any text - the name of the section
372
- // closing bracket
373
- const namedSectionLinkRegex = /\[\[([^\]]*?)\]\]\((.*?)\)/g;
374
- let links = allMatchesForGroup(input, namedSectionLinkRegex, 2).map(restore);
375
- checkSectionLinks(links, section, passage);
376
- input = input.replace(namedSectionLinkRegex, (_match, text /* $1 */, name /* $2 */) => {
377
- text = restore(text);
378
- const parsedName = getAdditionalLinkParameters(restore(name));
379
- return `{{section "${escapeForHandlebarsString(parsedName.target)}" text="${escapeForHandlebarsString(text)}"${parsedName.additionalParameters}}}`;
380
- });
381
- // namedPassageLinkRegex matches:
382
- // not preceded by ! (to avoid matching image links like ![alt](src))
383
- // open [
384
- // any text - the link text
385
- // closing ]
386
- // open bracket, but not http(s):// after it
387
- // any text - the name of the passage
388
- // closing bracket
389
- const namedPassageLinkRegex = /(?<!!)\[([^\]]*?)\]\(((?!https?:\/\/).*?)\)/g;
390
- links = allMatchesForGroup(input, namedPassageLinkRegex, 2).map(restore);
391
- checkPassageLinks(links, section, passage);
392
- input = input.replace(namedPassageLinkRegex, (_match, text /* $1 */, name /* $2 */) => {
393
- text = restore(text);
394
- const parsedName = getAdditionalLinkParameters(restore(name));
395
- return `{{passage "${escapeForHandlebarsString(parsedName.target)}" text="${escapeForHandlebarsString(text)}"${parsedName.additionalParameters}}}`;
396
- });
397
- // unnamedSectionLinkRegex matches:
398
- // open [[
399
- // any text - the link text
400
- // closing ]]
401
- const unnamedSectionLinkRegex = /\[\[(.*?)\]\]/g;
402
- links = allMatchesForGroup(input, unnamedSectionLinkRegex, 1).map(restore);
403
- checkSectionLinks(links, section, passage);
404
- input = input.replace(unnamedSectionLinkRegex, (_match, name) => `{{section "${escapeForHandlebarsString(restore(name))}"}}`);
405
- // unnamedPassageLinkRegex matches:
406
- // not preceded by ! (to avoid matching image links like ![alt])
407
- // open [
408
- // any text - the link text
409
- // closing ]
410
- // no bracket after
411
- const unnamedPassageLinkRegex = /(?<!!)\[(.*?)\]([^(]|$)/g;
412
- links = allMatchesForGroup(input, unnamedPassageLinkRegex, 1).map(restore);
413
- checkPassageLinks(links, section, passage);
414
- input = input.replace(unnamedPassageLinkRegex, (_match, name, suffix) => `{{passage "${escapeForHandlebarsString(restore(name))}"}}${suffix}`);
415
- input = restore(input);
416
- checkEmbeds(input, section, passage);
417
- return input;
418
- }
419
- function checkEmbeds(input, section, passage) {
420
- if (!settings.onWarning)
421
- return;
422
- // embedRegex matches {{embed "name"}} or {{embed 'name'}} with a literal name.
423
- // Like the runtime's embed helper, a name can refer to a passage in the
424
- // current section or to any section.
425
- const embedRegex = /\{\{~?\s*embed\s+(["'])(.*?)\1/g;
426
- const embeds = allMatchesForGroup(input, embedRegex, 2);
427
- const badEmbeds = embeds.filter(name => !(name in section.passages) && !(name in story.sections));
428
- for (const badEmbed of badEmbeds) {
429
- const location = passage
430
- ? `${section.filename} line ${passage.line}: In section '${section.name}', passage '${passage.name}'`
431
- : `${section.filename} line ${section.line}: In section '${section.name}'`;
432
- settings.onWarning(`WARNING: ${location} there is an embed of {{embed "${badEmbed}"}}, but no section or passage with that name exists`);
433
- }
434
- }
435
- function allMatchesForGroup(input, regex, groupNumber) {
436
- const result = [];
437
- let match;
438
- while ((match = regex.exec(input))) {
439
- result.push(match[groupNumber]);
440
- }
441
- return result;
442
- }
443
- function checkSectionLinks(links, section, passage) {
444
- const badLinks = links.filter(m => !linkDestinationExists(m, story.sections));
445
- showBadLinksWarning(badLinks, "section", "[[", "]]", section, passage);
446
- }
447
- function checkPassageLinks(links, section, passage) {
448
- const badLinks = links.filter(m => !linkDestinationExists(m, section.passages));
449
- showBadLinksWarning(badLinks, "passage", "[", "]", section, passage);
450
- }
451
- function linkDestinationExists(link, keys) {
452
- // Link destination data may look like:
453
- // passageName
454
- // passageName, my_attribute=2
455
- // passage name with a comma, in the name
456
- // We're only interested in checking if the named passage or section exists.
457
- // First check if the full link is a valid destination (handles names containing commas).
458
- const trimmedLink = link.trim();
459
- if (Object.keys(keys).includes(trimmedLink)) {
460
- return true;
461
- }
462
- // Otherwise, assume a comma separates the destination from setters.
463
- const linkDestination = trimmedLink.split(",")[0].trim();
464
- return Object.keys(keys).includes(linkDestination);
465
- }
466
- function showBadLinksWarning(badLinks, linkTo, before, after, section, passage) {
467
- if (!settings.onWarning)
468
- return;
469
- for (const badLink of badLinks) {
470
- let warning;
471
- if (!passage) {
472
- warning = `${section.filename} line ${section.line}: In section '${section.name}'`;
473
- }
474
- else {
475
- warning = `${section.filename} line ${passage.line}: In section '${section.name}', passage '${passage.name}'`;
476
- }
477
- settings.onWarning(`WARNING: ${warning} there is a link to a ${linkTo} called ${before}${badLink}${after}, which doesn't exist`);
478
- }
479
- }
480
- function writeJs(outputJsFile, tabCount, js) {
481
- const tabs = new Array(tabCount + 1).join("\t");
482
- outputJsFile.push(`${tabs}(squiffy, get, set) => {`);
483
- for (const jsLine of js) {
484
- outputJsFile.push(`${tabs}\t${jsLine}`);
485
- }
486
- outputJsFile.push(`${tabs}},`);
487
- }
488
- const success = await processFileText(settings.script, settings.scriptBaseFilename, true);
489
- if (success) {
490
- if (!Object.keys(story.sections).length) {
491
- ensureSectionExists(null, true, settings.scriptBaseFilename, 0);
492
- }
493
- const storyData = await getStoryData();
494
- return {
495
- success: true,
496
- output: storyData,
497
- getJs: (excludeHeader) => {
498
- return getJs(storyData, excludeHeader || false);
499
- },
500
- getUiInfo: () => {
501
- return {
502
- title: story.title,
503
- externalScripts: story.scripts,
504
- externalStylesheets: story.stylesheets,
505
- };
506
- }
507
- };
508
- }
509
- else {
20
+ if (!analysis.success) {
510
21
  return {
511
22
  success: false,
512
- errors: errors
23
+ errors: legacyErrors,
24
+ diagnostics: analysis.diagnostics,
513
25
  };
514
26
  }
515
- }
516
- class Story {
517
- constructor() {
518
- Object.defineProperty(this, "sections", {
519
- enumerable: true,
520
- configurable: true,
521
- writable: true,
522
- value: {}
523
- });
524
- Object.defineProperty(this, "title", {
525
- enumerable: true,
526
- configurable: true,
527
- writable: true,
528
- value: ""
529
- });
530
- Object.defineProperty(this, "scripts", {
531
- enumerable: true,
532
- configurable: true,
533
- writable: true,
534
- value: []
535
- });
536
- Object.defineProperty(this, "stylesheets", {
537
- enumerable: true,
538
- configurable: true,
539
- writable: true,
540
- value: []
541
- });
542
- Object.defineProperty(this, "start", {
543
- enumerable: true,
544
- configurable: true,
545
- writable: true,
546
- value: ""
547
- });
548
- Object.defineProperty(this, "id", {
549
- enumerable: true,
550
- configurable: true,
551
- writable: true,
552
- value: null
553
- });
554
- Object.defineProperty(this, "uiJs", {
555
- enumerable: true,
556
- configurable: true,
557
- writable: true,
558
- value: []
559
- });
560
- this.id = crypto.randomUUID();
561
- }
562
- addSection(name, filename, line) {
563
- const section = new Section(name, filename, line);
564
- this.sections[name] = section;
565
- return section;
566
- }
567
- addUiJs(text) {
568
- this.uiJs.push(text);
569
- }
570
- }
571
- class Section {
572
- constructor(name, filename, line) {
573
- Object.defineProperty(this, "name", {
574
- enumerable: true,
575
- configurable: true,
576
- writable: true,
577
- value: void 0
578
- });
579
- Object.defineProperty(this, "filename", {
580
- enumerable: true,
581
- configurable: true,
582
- writable: true,
583
- value: void 0
584
- });
585
- Object.defineProperty(this, "line", {
586
- enumerable: true,
587
- configurable: true,
588
- writable: true,
589
- value: void 0
590
- });
591
- Object.defineProperty(this, "text", {
592
- enumerable: true,
593
- configurable: true,
594
- writable: true,
595
- value: []
596
- });
597
- Object.defineProperty(this, "passages", {
598
- enumerable: true,
599
- configurable: true,
600
- writable: true,
601
- value: {}
602
- });
603
- Object.defineProperty(this, "js", {
604
- enumerable: true,
605
- configurable: true,
606
- writable: true,
607
- value: []
608
- });
609
- Object.defineProperty(this, "clear", {
610
- enumerable: true,
611
- configurable: true,
612
- writable: true,
613
- value: false
614
- });
615
- Object.defineProperty(this, "attributes", {
616
- enumerable: true,
617
- configurable: true,
618
- writable: true,
619
- value: []
620
- });
621
- this.name = name;
622
- this.filename = filename;
623
- this.line = line;
624
- }
625
- addPassage(name, line) {
626
- const passage = new Passage(name, line);
627
- this.passages[name] = passage;
628
- return passage;
629
- }
630
- addText(text) {
631
- this.text.push(text);
632
- }
633
- addJS(text) {
634
- this.js.push(text);
635
- }
636
- addAttribute(text) {
637
- this.attributes.push(text);
638
- }
639
- }
640
- class Passage {
641
- constructor(name, line) {
642
- Object.defineProperty(this, "name", {
643
- enumerable: true,
644
- configurable: true,
645
- writable: true,
646
- value: void 0
647
- });
648
- Object.defineProperty(this, "line", {
649
- enumerable: true,
650
- configurable: true,
651
- writable: true,
652
- value: void 0
653
- });
654
- Object.defineProperty(this, "text", {
655
- enumerable: true,
656
- configurable: true,
657
- writable: true,
658
- value: []
659
- });
660
- Object.defineProperty(this, "js", {
661
- enumerable: true,
662
- configurable: true,
663
- writable: true,
664
- value: []
665
- });
666
- Object.defineProperty(this, "clear", {
667
- enumerable: true,
668
- configurable: true,
669
- writable: true,
670
- value: false
671
- });
672
- Object.defineProperty(this, "attributes", {
673
- enumerable: true,
674
- configurable: true,
675
- writable: true,
676
- value: []
677
- });
678
- this.name = name;
679
- this.line = line;
680
- }
681
- addText(text) {
682
- this.text.push(text);
683
- }
684
- addJS(text) {
685
- this.js.push(text);
686
- }
687
- addAttribute(text) {
688
- this.attributes.push(text);
689
- }
27
+ return emit(analysis, { globalJs: settings.globalJs });
690
28
  }