squiffy-compiler 6.0.1 → 7.0.0-beta.11
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 +10 -2
- package/dist/analyse.d.ts +96 -0
- package/dist/analyse.js +951 -0
- package/dist/compiler.d.ts +32 -40
- package/dist/compiler.js +26 -691
- package/dist/css-urls.d.ts +4 -0
- package/dist/css-urls.js +59 -0
- package/dist/emit.d.ts +71 -0
- package/dist/emit.js +192 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +14 -0
- package/dist/ignore.d.ts +8 -0
- package/dist/ignore.js +71 -0
- package/dist/infix-expressions.d.ts +19 -0
- package/dist/infix-expressions.js +713 -0
- package/dist/language-service.d.ts +90 -0
- package/dist/language-service.js +883 -0
- package/dist/node.d.ts +23 -0
- package/dist/node.js +122 -0
- package/dist/parse.d.ts +22 -0
- package/dist/parse.js +316 -0
- package/dist/project.d.ts +129 -0
- package/dist/project.js +488 -0
- package/dist/quest/aslx.d.ts +51 -0
- package/dist/quest/aslx.js +184 -0
- package/dist/quest/convert.d.ts +20 -0
- package/dist/quest/convert.js +552 -0
- package/dist/quest/script.d.ts +92 -0
- package/dist/quest/script.js +453 -0
- package/dist/quest/scripts.d.ts +24 -0
- package/dist/quest/scripts.js +506 -0
- package/dist/quest/text.d.ts +18 -0
- package/dist/quest/text.js +323 -0
- package/dist/section-labels.d.ts +4 -0
- package/dist/section-labels.js +64 -0
- package/dist/setters.d.ts +49 -0
- package/dist/setters.js +477 -0
- package/dist/story-graph.d.ts +71 -0
- package/dist/story-graph.js +445 -0
- package/dist/syntax.d.ts +198 -0
- package/dist/syntax.js +8 -0
- package/dist/templates.d.ts +17 -0
- package/dist/templates.js +180 -0
- package/dist/text.d.ts +44 -0
- package/dist/text.js +348 -0
- package/dist/twine/audio.d.ts +21 -0
- package/dist/twine/audio.js +80 -0
- package/dist/twine/convert.d.ts +131 -0
- package/dist/twine/convert.js +1057 -0
- package/dist/twine/expression.d.ts +88 -0
- package/dist/twine/expression.js +318 -0
- package/dist/twine/harlowe.d.ts +27 -0
- package/dist/twine/harlowe.js +2341 -0
- package/dist/twine/settings.d.ts +9 -0
- package/dist/twine/settings.js +322 -0
- package/dist/twine/story.d.ts +24 -0
- package/dist/twine/story.js +231 -0
- package/dist/twine/sugarcube.d.ts +40 -0
- package/dist/twine/sugarcube.js +2172 -0
- package/dist/v5.js +2 -1
- package/package.json +35 -6
- package/syntaxes/squiffy.tmLanguage.json +1003 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isRelativeUrl(url: string): boolean;
|
|
2
|
+
export declare function rewriteCssUrls(css: string, replace: (url: string) => string | undefined): string;
|
|
3
|
+
export declare function findCssUrls(css: string): string[];
|
|
4
|
+
export declare function resolveCssUrl(sheetPath: string, url: string): string | null;
|
package/dist/css-urls.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The url()s in a story's own stylesheets, such as a font's files or a background image. A
|
|
2
|
+
// stylesheet refers to them by their path from its own folder, as a web page's CSS does. That
|
|
3
|
+
// works as it is in a published story, whose stylesheets are separate files, but a one-file
|
|
4
|
+
// export or the editor's preview has to swap each for something it can load.
|
|
5
|
+
const URL_PATTERN = /url\(\s*(?:"((?:[^"\\\n]|\\.)*)"|'((?:[^'\\\n]|\\.)*)'|([^)"'\s]*))\s*\)/gi;
|
|
6
|
+
// A url() that's a path to a file beside the stylesheet, rather than a web address, a data: URI,
|
|
7
|
+
// an absolute path or a reference to an SVG element like "#gradient"
|
|
8
|
+
export function isRelativeUrl(url) {
|
|
9
|
+
return url != "" && !/^(?:[a-z][a-z\d+.-]*:|\/|#)/i.test(url);
|
|
10
|
+
}
|
|
11
|
+
// Replaces each relative url() in css with what replace returns for it, or leaves it as it is if
|
|
12
|
+
// replace returns undefined
|
|
13
|
+
export function rewriteCssUrls(css, replace) {
|
|
14
|
+
return css.replace(URL_PATTERN, (match, double, single, bare) => {
|
|
15
|
+
const url = (double ?? single ?? bare ?? "").trim();
|
|
16
|
+
if (!isRelativeUrl(url))
|
|
17
|
+
return match;
|
|
18
|
+
const replacement = replace(url);
|
|
19
|
+
return replacement === undefined ? match : `url("${replacement.replace(/["\\\n]/g, c => c == "\n" ? "\\a " : `\\${c}`)}")`;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// The relative url()s in css
|
|
23
|
+
export function findCssUrls(css) {
|
|
24
|
+
const urls = [];
|
|
25
|
+
rewriteCssUrls(css, url => {
|
|
26
|
+
urls.push(url);
|
|
27
|
+
return undefined;
|
|
28
|
+
});
|
|
29
|
+
return urls;
|
|
30
|
+
}
|
|
31
|
+
// The path, from the story's folder, of a url() in the stylesheet at sheetPath (also from the
|
|
32
|
+
// story's folder), e.g. "fonts/literata/latin-400-normal.woff2" for "latin-400-normal.woff2" in
|
|
33
|
+
// "fonts/literata/literata.css". Null if it's outside the story's folder. A query or #fragment,
|
|
34
|
+
// such as the "?#iefix" some older @font-face rules have, isn't part of the path.
|
|
35
|
+
export function resolveCssUrl(sheetPath, url) {
|
|
36
|
+
let path = url.replace(/[?#].*$/, "");
|
|
37
|
+
try {
|
|
38
|
+
path = decodeURI(path);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Not valid percent-encoding: use it as it is
|
|
42
|
+
}
|
|
43
|
+
const sheet = sheetPath.replace(/\\/g, "/").split("/");
|
|
44
|
+
sheet.pop();
|
|
45
|
+
const parts = sheet.filter(part => part != "" && part != ".");
|
|
46
|
+
for (const part of path.replace(/\\/g, "/").split("/")) {
|
|
47
|
+
if (part == "" || part == ".")
|
|
48
|
+
continue;
|
|
49
|
+
if (part == "..") {
|
|
50
|
+
if (!parts.length || parts[parts.length - 1] == "..")
|
|
51
|
+
return null;
|
|
52
|
+
parts.pop();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
parts.push(part);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return parts.length ? parts.join("/") : null;
|
|
59
|
+
}
|
package/dist/emit.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Analysis } from "./analyse.js";
|
|
2
|
+
import type { Diagnostic } from "./syntax.js";
|
|
3
|
+
import type { Panel, PlayerSetting } from "./project.js";
|
|
4
|
+
export interface Output {
|
|
5
|
+
story: OutputStory;
|
|
6
|
+
js: string[][];
|
|
7
|
+
}
|
|
8
|
+
interface OutputStory {
|
|
9
|
+
start: string;
|
|
10
|
+
id: string | null;
|
|
11
|
+
projectId?: string;
|
|
12
|
+
uiJsIndex?: number;
|
|
13
|
+
expressions?: boolean;
|
|
14
|
+
panels?: Panel[];
|
|
15
|
+
settings?: PlayerSetting[];
|
|
16
|
+
persistent?: string[];
|
|
17
|
+
sections: Record<string, OutputSection>;
|
|
18
|
+
audio?: string[];
|
|
19
|
+
}
|
|
20
|
+
interface OutputSection {
|
|
21
|
+
text?: string;
|
|
22
|
+
clear?: boolean;
|
|
23
|
+
music?: string | null;
|
|
24
|
+
sounds?: string[];
|
|
25
|
+
classes?: string[];
|
|
26
|
+
tags?: string[];
|
|
27
|
+
transition?: string;
|
|
28
|
+
transitionTime?: number;
|
|
29
|
+
leave?: string;
|
|
30
|
+
leaveTime?: number;
|
|
31
|
+
attributes?: string[];
|
|
32
|
+
jsIndex?: number;
|
|
33
|
+
passages?: Record<string, OutputPassage>;
|
|
34
|
+
passageCount?: number;
|
|
35
|
+
}
|
|
36
|
+
interface OutputPassage {
|
|
37
|
+
text?: string;
|
|
38
|
+
clear?: boolean;
|
|
39
|
+
music?: string | null;
|
|
40
|
+
sounds?: string[];
|
|
41
|
+
classes?: string[];
|
|
42
|
+
tags?: string[];
|
|
43
|
+
transition?: string;
|
|
44
|
+
transitionTime?: number;
|
|
45
|
+
leave?: string;
|
|
46
|
+
leaveTime?: number;
|
|
47
|
+
repeat?: boolean;
|
|
48
|
+
attributes?: string[];
|
|
49
|
+
jsIndex?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface UiInfo {
|
|
52
|
+
title: string;
|
|
53
|
+
externalScripts: string[];
|
|
54
|
+
externalStylesheets: string[];
|
|
55
|
+
}
|
|
56
|
+
export interface EmitSettings {
|
|
57
|
+
globalJs?: boolean;
|
|
58
|
+
projectId?: string;
|
|
59
|
+
panels?: Panel[];
|
|
60
|
+
settings?: PlayerSetting[];
|
|
61
|
+
persistent?: string[];
|
|
62
|
+
}
|
|
63
|
+
export interface CompileSuccess {
|
|
64
|
+
success: true;
|
|
65
|
+
output: Output;
|
|
66
|
+
getJs: (excludeHeader?: boolean) => Promise<string>;
|
|
67
|
+
getUiInfo: () => UiInfo;
|
|
68
|
+
diagnostics: Diagnostic[];
|
|
69
|
+
}
|
|
70
|
+
export declare function emit(analysis: Analysis, settings?: EmitSettings): CompileSuccess;
|
|
71
|
+
export {};
|
package/dist/emit.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import pkg from "../package.json" with { type: "json" };
|
|
2
|
+
import { analysisInternals } from "./analyse.js";
|
|
3
|
+
const version = pkg.version;
|
|
4
|
+
// {{music "file"}} or {{sound "file"}}
|
|
5
|
+
const SOUND_HELPER = /\{\{\s*(?:music|sound)\s+(["'])([^"'{}]+)\1/g;
|
|
6
|
+
// @music and @sound (#444), and the files they and the text name, for OutputStory.audio
|
|
7
|
+
function addSounds(output, from, audio) {
|
|
8
|
+
if (from.music !== undefined)
|
|
9
|
+
output.music = from.music;
|
|
10
|
+
if (from.sounds.length)
|
|
11
|
+
output.sounds = from.sounds;
|
|
12
|
+
if (from.music)
|
|
13
|
+
audio.add(from.music);
|
|
14
|
+
from.sounds.forEach(file => { if (file != "stop")
|
|
15
|
+
audio.add(file); });
|
|
16
|
+
for (const match of from.output.matchAll(SOUND_HELPER))
|
|
17
|
+
audio.add(match[2]);
|
|
18
|
+
}
|
|
19
|
+
function addTransition(output, from) {
|
|
20
|
+
if (from.transition !== undefined)
|
|
21
|
+
output.transition = from.transition;
|
|
22
|
+
if (from.transitionTime !== undefined)
|
|
23
|
+
output.transitionTime = from.transitionTime;
|
|
24
|
+
if (from.leave !== undefined)
|
|
25
|
+
output.leave = from.leave;
|
|
26
|
+
if (from.leaveTime !== undefined)
|
|
27
|
+
output.leaveTime = from.leaveTime;
|
|
28
|
+
}
|
|
29
|
+
// Produces the story data and JavaScript for an analysis that succeeded.
|
|
30
|
+
export function emit(analysis, settings = {}) {
|
|
31
|
+
const internals = analysisInternals.get(analysis);
|
|
32
|
+
if (!internals) {
|
|
33
|
+
throw new Error("emit() needs the result of analyse()");
|
|
34
|
+
}
|
|
35
|
+
if (!analysis.success) {
|
|
36
|
+
throw new Error("Can't emit a story whose analysis has errors");
|
|
37
|
+
}
|
|
38
|
+
const story = internals.story;
|
|
39
|
+
const output = {
|
|
40
|
+
story: {
|
|
41
|
+
start: story.start,
|
|
42
|
+
id: story.id,
|
|
43
|
+
sections: {},
|
|
44
|
+
},
|
|
45
|
+
js: [],
|
|
46
|
+
};
|
|
47
|
+
if (analysis.expressions) {
|
|
48
|
+
output.story.expressions = true;
|
|
49
|
+
}
|
|
50
|
+
if (settings.projectId) {
|
|
51
|
+
output.story.projectId = settings.projectId;
|
|
52
|
+
}
|
|
53
|
+
if (settings.panels?.length) {
|
|
54
|
+
output.story.panels = settings.panels;
|
|
55
|
+
}
|
|
56
|
+
if (settings.settings?.length) {
|
|
57
|
+
output.story.settings = settings.settings;
|
|
58
|
+
}
|
|
59
|
+
if (settings.persistent?.length) {
|
|
60
|
+
output.story.persistent = settings.persistent;
|
|
61
|
+
}
|
|
62
|
+
if (story.uiJs.length > 0) {
|
|
63
|
+
output.js.push(story.uiJs);
|
|
64
|
+
output.story.uiJsIndex = output.js.length - 1;
|
|
65
|
+
}
|
|
66
|
+
const audio = new Set();
|
|
67
|
+
for (const sectionName of Object.keys(story.sections)) {
|
|
68
|
+
const section = story.sections[sectionName];
|
|
69
|
+
const outputSection = {};
|
|
70
|
+
output.story.sections[sectionName] = outputSection;
|
|
71
|
+
if (section.clear) {
|
|
72
|
+
outputSection.clear = true;
|
|
73
|
+
}
|
|
74
|
+
outputSection.text = section.output;
|
|
75
|
+
addSounds(outputSection, section, audio);
|
|
76
|
+
if (section.classes.length)
|
|
77
|
+
outputSection.classes = section.classes;
|
|
78
|
+
if (section.tags.length)
|
|
79
|
+
outputSection.tags = section.tags;
|
|
80
|
+
addTransition(outputSection, section);
|
|
81
|
+
if (section.attributes.length > 0) {
|
|
82
|
+
outputSection.attributes = section.attributes;
|
|
83
|
+
}
|
|
84
|
+
if (section.js.length > 0) {
|
|
85
|
+
output.js.push(section.js);
|
|
86
|
+
outputSection.jsIndex = output.js.length - 1;
|
|
87
|
+
}
|
|
88
|
+
if ("@last" in section.passages) {
|
|
89
|
+
let passageCount = 0;
|
|
90
|
+
for (const passageName of Object.keys(section.passages)) {
|
|
91
|
+
// A passage with @repeat doesn't count, as clicking it doesn't use it up
|
|
92
|
+
if (passageName.length > 0 && passageName?.substring(0, 1) !== "@" && !section.passages[passageName].repeat) {
|
|
93
|
+
passageCount++;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
outputSection.passageCount = passageCount;
|
|
97
|
+
}
|
|
98
|
+
if (Object.keys(section.passages).length == 0)
|
|
99
|
+
continue;
|
|
100
|
+
outputSection.passages = {};
|
|
101
|
+
for (const passageName of Object.keys(section.passages)) {
|
|
102
|
+
const passage = section.passages[passageName];
|
|
103
|
+
const outputPassage = {};
|
|
104
|
+
outputSection.passages[passageName] = outputPassage;
|
|
105
|
+
if (passage.clear) {
|
|
106
|
+
outputPassage.clear = true;
|
|
107
|
+
}
|
|
108
|
+
if (passage.repeat) {
|
|
109
|
+
outputPassage.repeat = true;
|
|
110
|
+
}
|
|
111
|
+
outputPassage.text = passage.output;
|
|
112
|
+
addSounds(outputPassage, passage, audio);
|
|
113
|
+
if (passage.classes.length)
|
|
114
|
+
outputPassage.classes = passage.classes;
|
|
115
|
+
if (passage.tags.length)
|
|
116
|
+
outputPassage.tags = passage.tags;
|
|
117
|
+
addTransition(outputPassage, passage);
|
|
118
|
+
if (passage.attributes.length > 0) {
|
|
119
|
+
outputPassage.attributes = passage.attributes;
|
|
120
|
+
}
|
|
121
|
+
if (passage.js.length > 0) {
|
|
122
|
+
output.js.push(passage.js);
|
|
123
|
+
outputPassage.jsIndex = output.js.length - 1;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (audio.size) {
|
|
128
|
+
output.story.audio = [...audio];
|
|
129
|
+
}
|
|
130
|
+
const getJs = async (excludeHeader) => {
|
|
131
|
+
const outputJs = [];
|
|
132
|
+
if (!excludeHeader) {
|
|
133
|
+
outputJs.push(`// Created with Squiffy ${version}`);
|
|
134
|
+
outputJs.push("// https://github.com/textadventures/squiffy");
|
|
135
|
+
}
|
|
136
|
+
if (settings.globalJs) {
|
|
137
|
+
outputJs.push("var story = {};");
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
outputJs.push("export const story = {};");
|
|
141
|
+
}
|
|
142
|
+
outputJs.push(`story.id = ${JSON.stringify(output.story.id, null, 4)};`);
|
|
143
|
+
if (output.story.projectId) {
|
|
144
|
+
outputJs.push(`story.projectId = ${JSON.stringify(output.story.projectId)};`);
|
|
145
|
+
}
|
|
146
|
+
if (output.story.uiJsIndex !== undefined) {
|
|
147
|
+
outputJs.push(`story.uiJsIndex = ${output.story.uiJsIndex};`);
|
|
148
|
+
}
|
|
149
|
+
if (output.story.expressions) {
|
|
150
|
+
outputJs.push("story.expressions = true;");
|
|
151
|
+
}
|
|
152
|
+
if (output.story.panels) {
|
|
153
|
+
outputJs.push(`story.panels = ${JSON.stringify(output.story.panels, null, 4)};`);
|
|
154
|
+
}
|
|
155
|
+
if (output.story.settings) {
|
|
156
|
+
outputJs.push(`story.settings = ${JSON.stringify(output.story.settings, null, 4)};`);
|
|
157
|
+
}
|
|
158
|
+
if (output.story.persistent) {
|
|
159
|
+
outputJs.push(`story.persistent = ${JSON.stringify(output.story.persistent)};`);
|
|
160
|
+
}
|
|
161
|
+
if (output.story.audio) {
|
|
162
|
+
outputJs.push(`story.audio = ${JSON.stringify(output.story.audio, null, 4)};`);
|
|
163
|
+
}
|
|
164
|
+
outputJs.push(`story.start = ${JSON.stringify(output.story.start, null, 4)};`);
|
|
165
|
+
outputJs.push(`story.sections = ${JSON.stringify(output.story.sections, null, 4)};`);
|
|
166
|
+
outputJs.push("story.js = [");
|
|
167
|
+
for (const js of output.js) {
|
|
168
|
+
writeJs(outputJs, 1, js);
|
|
169
|
+
}
|
|
170
|
+
outputJs.push("];");
|
|
171
|
+
return outputJs.join("\n");
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
success: true,
|
|
175
|
+
output,
|
|
176
|
+
getJs: (excludeHeader) => getJs(excludeHeader || false),
|
|
177
|
+
getUiInfo: () => ({
|
|
178
|
+
title: story.title,
|
|
179
|
+
externalScripts: story.scripts,
|
|
180
|
+
externalStylesheets: story.stylesheets,
|
|
181
|
+
}),
|
|
182
|
+
diagnostics: analysis.diagnostics,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function writeJs(outputJsFile, tabCount, js) {
|
|
186
|
+
const tabs = new Array(tabCount + 1).join("\t");
|
|
187
|
+
outputJsFile.push(`${tabs}(squiffy, get, set) => {`);
|
|
188
|
+
for (const jsLine of js) {
|
|
189
|
+
outputJsFile.push(`${tabs}\t${jsLine}`);
|
|
190
|
+
}
|
|
191
|
+
outputJsFile.push(`${tabs}},`);
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const BUILT_IN_HELPERS: ReadonlySet<string>;
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The helpers the runtime registers, and Handlebars' own, so that the compiler can tell a helper
|
|
2
|
+
// from an attribute in {{name}}. runtime/src/helpers.test.ts fails if this goes out of date.
|
|
3
|
+
export const BUILT_IN_HELPERS = new Set([
|
|
4
|
+
// Handlebars' own
|
|
5
|
+
"each", "if", "unless", "with", "log", "lookup",
|
|
6
|
+
// The runtime's
|
|
7
|
+
"abs", "add", "addclass", "and", "animate", "append", "array", "at", "capitalise", "capitalize", "ceil",
|
|
8
|
+
"clear", "cond", "contains", "content", "count", "deactivate", "dec", "div", "embed", "eq", "every", "first",
|
|
9
|
+
"firsttime", "floor", "forget", "get", "goto", "gt", "gte", "hasclass", "inc", "indexof", "join", "label", "last", "lastvisited",
|
|
10
|
+
"length", "live", "lower", "lt", "lte", "max", "min", "mod", "mul", "music", "ne", "not", "once", "or",
|
|
11
|
+
"passage", "passages", "pop", "prepend", "random", "range", "remove", "removeclass", "replace", "restart", "rotate",
|
|
12
|
+
"round", "saves", "section", "sections", "seen", "sequence", "set", "settings", "shuffle", "slice", "sort",
|
|
13
|
+
"sound", "stop", "stopmusic", "stopsounds", "style", "sub", "tags", "toggleclass", "unset", "upper", "visits",
|
|
14
|
+
]);
|
package/dist/ignore.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Diagnostic, Range, SectionNode, SquiffyFile } from "./syntax.js";
|
|
2
|
+
export interface IgnoreComment {
|
|
3
|
+
code: string;
|
|
4
|
+
subjects: string[];
|
|
5
|
+
range: Range;
|
|
6
|
+
}
|
|
7
|
+
export declare function findIgnoreComments(section: SectionNode): IgnoreComment[];
|
|
8
|
+
export declare function ignoredDiagnostics(files: SquiffyFile[], diagnostics: Diagnostic[]): Set<Diagnostic>;
|
package/dist/ignore.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const IGNORE_COMMENT = /\{\{~?!(?:--)?\s*squiffy-ignore\b([\s\S]*?)(?:--)?~?\}\}/g;
|
|
2
|
+
// The squiffy-ignore comments in a section, its passages included
|
|
3
|
+
export function findIgnoreComments(section) {
|
|
4
|
+
const result = [];
|
|
5
|
+
for (const container of [section, ...section.passages]) {
|
|
6
|
+
for (const statement of container.body) {
|
|
7
|
+
if (statement.type != "text")
|
|
8
|
+
continue;
|
|
9
|
+
for (const match of statement.text.matchAll(IGNORE_COMMENT)) {
|
|
10
|
+
const [code, ...subjects] = match[1].split(/[\s,]+/).filter(Boolean);
|
|
11
|
+
if (!code)
|
|
12
|
+
continue;
|
|
13
|
+
const line = statement.range.start.line;
|
|
14
|
+
const character = statement.range.start.character + match.index;
|
|
15
|
+
result.push({
|
|
16
|
+
code: code.startsWith("squiffy/") ? code : `squiffy/${code}`,
|
|
17
|
+
subjects,
|
|
18
|
+
range: { start: { line, character }, end: { line, character: character + match[0].length } },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
const isMaster = (section) => section.header?.type == "section-header" && section.header.name == "";
|
|
26
|
+
const matches = (comment, diagnostic) => comment.code == diagnostic.code
|
|
27
|
+
&& (!comment.subjects.length || (diagnostic.subject !== undefined && comment.subjects.includes(diagnostic.subject)));
|
|
28
|
+
// The section a position in a file is in: the last one that starts on or before its line
|
|
29
|
+
function sectionAt(file, line) {
|
|
30
|
+
let current = file.preamble;
|
|
31
|
+
for (const node of file.sections) {
|
|
32
|
+
if (node.range.start.line <= line)
|
|
33
|
+
current = node;
|
|
34
|
+
}
|
|
35
|
+
return current.type == "section" ? current : undefined;
|
|
36
|
+
}
|
|
37
|
+
// The warnings and hints that squiffy-ignore comments turn off
|
|
38
|
+
export function ignoredDiagnostics(files, diagnostics) {
|
|
39
|
+
const ignored = new Set();
|
|
40
|
+
const bySection = new Map();
|
|
41
|
+
const everywhere = [];
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
for (const section of [file.preamble, ...file.sections]) {
|
|
44
|
+
if (section.type != "section")
|
|
45
|
+
continue;
|
|
46
|
+
const comments = findIgnoreComments(section);
|
|
47
|
+
if (!comments.length)
|
|
48
|
+
continue;
|
|
49
|
+
if (isMaster(section))
|
|
50
|
+
everywhere.push(...comments);
|
|
51
|
+
else
|
|
52
|
+
bySection.set(section, comments);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!everywhere.length && !bySection.size)
|
|
56
|
+
return ignored;
|
|
57
|
+
const fileNamed = new Map(files.map(f => [f.filename ?? "", f]));
|
|
58
|
+
for (const diagnostic of diagnostics) {
|
|
59
|
+
if (diagnostic.severity == "error")
|
|
60
|
+
continue;
|
|
61
|
+
if (everywhere.some(c => matches(c, diagnostic))) {
|
|
62
|
+
ignored.add(diagnostic);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const file = fileNamed.get(diagnostic.file);
|
|
66
|
+
const section = file && sectionAt(file, diagnostic.range.start.line);
|
|
67
|
+
if (section && bySection.get(section)?.some(c => matches(c, diagnostic)))
|
|
68
|
+
ignored.add(diagnostic);
|
|
69
|
+
}
|
|
70
|
+
return ignored;
|
|
71
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function rewriteInfixCondition(condition: string): string | null;
|
|
2
|
+
export declare function rewriteInfixArguments(args: string): string | null;
|
|
3
|
+
export declare function rewriteInfixEmbed(args: string, label?: string): string | null;
|
|
4
|
+
export declare function rewriteDisplayExpression(expression: string): string;
|
|
5
|
+
export declare function rewriteValueExpression(expression: string): string;
|
|
6
|
+
export declare function splitSetters(setters: string): string[];
|
|
7
|
+
export declare function findTagEnd(text: string, from: number): number;
|
|
8
|
+
export declare class InfixRewriteError extends Error {
|
|
9
|
+
readonly start: number;
|
|
10
|
+
readonly end: number;
|
|
11
|
+
constructor(message: string, start: number, end: number);
|
|
12
|
+
}
|
|
13
|
+
export interface InfixEdit {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
length: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function rewriteInfixExpressions(text: string, edits?: InfixEdit[]): string;
|
|
19
|
+
export declare function mapRewrittenPosition(edits: InfixEdit[], pos: number): number;
|