storm-lua-minify 0.2.0 → 0.3.0
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/LICENSE +21 -21
- package/README.md +79 -37
- package/dist/ast2lua.js +67 -14
- package/dist/cli.js +28 -2
- package/dist/globalRename.js +35 -0
- package/dist/keywordLocator.js +68 -0
- package/dist/linker.js +13 -0
- package/dist/minifier.js +75 -1
- package/dist/renamer.js +16 -2
- package/dist/resolver.js +10 -4
- package/dist/transform.js +401 -0
- package/package.json +41 -33
- package/.github/workflows/ci.yml +0 -39
- package/.github/workflows/publish.yml +0 -39
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -1
- package/eslint.config.js +0 -29
- package/src/ast2lua.ts +0 -940
- package/src/cli.ts +0 -86
- package/src/linker.ts +0 -108
- package/src/minifier.ts +0 -284
- package/src/output.ts +0 -71
- package/src/renamer.ts +0 -134
- package/src/resolver.ts +0 -378
- package/test/circular-require.test.ts +0 -19
- package/test/fixtures/bare-require/main.lua +0 -2
- package/test/fixtures/bare-require/mod.lua +0 -1
- package/test/fixtures/bitwise-precedence/main.lua +0 -10
- package/test/fixtures/circular-require/a.lua +0 -2
- package/test/fixtures/circular-require/b.lua +0 -2
- package/test/fixtures/circular-require/main.lua +0 -2
- package/test/fixtures/dofile/greet.lua +0 -1
- package/test/fixtures/dofile/main.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_alpha.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_bravo.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_charlie.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_delta.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_echo.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_foxtrot.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_golf.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_hotel.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_india.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_juliet.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/dep_kilo.lua +0 -2
- package/test/fixtures/entry-scope-many-requires/main.lua +0 -25
- package/test/fixtures/multi-require/common.lua +0 -1
- package/test/fixtures/multi-require/main.lua +0 -3
- package/test/fixtures/nested-module/main.lua +0 -2
- package/test/fixtures/nested-module/sub/deep.lua +0 -1
- package/test/fixtures/require-call/main.lua +0 -2
- package/test/fixtures/require-call/mod.lua +0 -5
- package/test/fixtures/require-in-expression/main.lua +0 -1
- package/test/fixtures/require-in-expression/mod.lua +0 -1
- package/test/fixtures/require-string-call/main.lua +0 -2
- package/test/fixtures/require-string-call/mod.lua +0 -5
- package/test/fixtures/single-file/main.lua +0 -15
- package/test/identifier-collision.test.ts +0 -28
- package/test/lib/collision.ts +0 -131
- package/test/lib/helpers.ts +0 -124
- package/test/no-rename.test.ts +0 -19
- package/test/output.test.ts +0 -95
- package/test/precedence.test.ts +0 -28
- package/test/renamer.test.ts +0 -130
- package/test/resolver.test.ts +0 -206
- package/test/roundtrip.test.ts +0 -26
- package/test/snapshot.test.ts +0 -27
- package/test/snapshots/bare-require.sl.lua +0 -1
- package/test/snapshots/bitwise-precedence.sl.lua +0 -2
- package/test/snapshots/dofile.sl.lua +0 -1
- package/test/snapshots/entry-scope-many-requires.m.lua +0 -14
- package/test/snapshots/multi-require.m.lua +0 -4
- package/test/snapshots/multi-require.sl.lua +0 -1
- package/test/snapshots/nested-module.m.lua +0 -4
- package/test/snapshots/require-call.m.lua +0 -5
- package/test/snapshots/require-call.sl.lua +0 -1
- package/test/snapshots/require-in-expression.sl.lua +0 -1
- package/test/snapshots/require-string-call.m.lua +0 -5
- package/test/snapshots/single-file.sl.lua +0 -6
- package/test/sourcemap.test.ts +0 -105
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -111
package/src/resolver.ts
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
// Resolveパス(#19): 宣言ごとに一意なシンボルを持つスコープツリーを構築し、
|
|
2
|
-
// 識別子の参照を対応する宣言シンボルに解決する。グローバル参照も識別する。
|
|
3
|
-
// このパスは解析のみを行い、ASTやその出力を一切変更しない。
|
|
4
|
-
import Parser from "luaparse";
|
|
5
|
-
|
|
6
|
-
export type SymbolKind = "local" | "param" | "for" | "label";
|
|
7
|
-
|
|
8
|
-
export interface Scope {
|
|
9
|
-
readonly kind: "chunk" | "function" | "block";
|
|
10
|
-
readonly parent: Scope | null;
|
|
11
|
-
readonly children: Scope[];
|
|
12
|
-
// このスコープで直接宣言されたシンボル(宣言順。同名の再宣言もすべて含む)
|
|
13
|
-
readonly symbols: Symbol[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Symbol {
|
|
17
|
-
readonly id: number;
|
|
18
|
-
readonly name: string;
|
|
19
|
-
readonly kind: SymbolKind;
|
|
20
|
-
readonly scope: Scope;
|
|
21
|
-
readonly declaration: Parser.Identifier;
|
|
22
|
-
// このシンボルを指す参照(宣言箇所自体は含まない)
|
|
23
|
-
readonly references: Parser.Identifier[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface GlobalBinding {
|
|
27
|
-
readonly name: string;
|
|
28
|
-
readonly references: Parser.Identifier[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface ResolveResult {
|
|
32
|
-
readonly chunkScope: Scope;
|
|
33
|
-
// チャンク全体で宣言された全シンボル(宣言順)
|
|
34
|
-
readonly symbols: Symbol[];
|
|
35
|
-
readonly globals: Map<string, GlobalBinding>;
|
|
36
|
-
// 宣言・参照どちらの識別子ノードからも対応するシンボルを引ける。
|
|
37
|
-
// グローバル参照やフィールド名など、シンボルを持たない識別子はundefinedを返す。
|
|
38
|
-
symbolOf(identifier: Parser.Identifier): Symbol | undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface MutableScope extends Scope {
|
|
42
|
-
readonly parent: MutableScope | null;
|
|
43
|
-
readonly children: MutableScope[];
|
|
44
|
-
readonly bindings: Map<string, Symbol>;
|
|
45
|
-
readonly labels: Map<string, Symbol>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function resolveScopes(chunk: Parser.Chunk): ResolveResult {
|
|
49
|
-
let nextSymbolId = 0;
|
|
50
|
-
const allSymbols: Symbol[] = [];
|
|
51
|
-
const globals = new Map<string, GlobalBinding>();
|
|
52
|
-
const identifierSymbols = new WeakMap<Parser.Identifier, Symbol>();
|
|
53
|
-
|
|
54
|
-
function createScope(
|
|
55
|
-
kind: Scope["kind"],
|
|
56
|
-
parent: MutableScope | null,
|
|
57
|
-
): MutableScope {
|
|
58
|
-
const scope: MutableScope = {
|
|
59
|
-
kind,
|
|
60
|
-
parent,
|
|
61
|
-
children: [],
|
|
62
|
-
symbols: [],
|
|
63
|
-
bindings: new Map(),
|
|
64
|
-
labels: new Map(),
|
|
65
|
-
};
|
|
66
|
-
parent?.children.push(scope);
|
|
67
|
-
return scope;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function declare(
|
|
71
|
-
scope: MutableScope,
|
|
72
|
-
node: Parser.Identifier,
|
|
73
|
-
kind: SymbolKind,
|
|
74
|
-
): Symbol {
|
|
75
|
-
const symbol: Symbol = {
|
|
76
|
-
id: nextSymbolId++,
|
|
77
|
-
name: node.name,
|
|
78
|
-
kind,
|
|
79
|
-
scope,
|
|
80
|
-
declaration: node,
|
|
81
|
-
references: [],
|
|
82
|
-
};
|
|
83
|
-
// 同名の再宣言はスコープ内の以後の参照から見た束縛を上書きする(Luaの通常のシャドーイング)
|
|
84
|
-
scope.symbols.push(symbol);
|
|
85
|
-
scope.bindings.set(node.name, symbol);
|
|
86
|
-
allSymbols.push(symbol);
|
|
87
|
-
identifierSymbols.set(node, symbol);
|
|
88
|
-
return symbol;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function declareLabel(scope: MutableScope, node: Parser.Identifier): Symbol {
|
|
92
|
-
const symbol: Symbol = {
|
|
93
|
-
id: nextSymbolId++,
|
|
94
|
-
name: node.name,
|
|
95
|
-
kind: "label",
|
|
96
|
-
scope,
|
|
97
|
-
declaration: node,
|
|
98
|
-
references: [],
|
|
99
|
-
};
|
|
100
|
-
scope.symbols.push(symbol);
|
|
101
|
-
scope.labels.set(node.name, symbol);
|
|
102
|
-
allSymbols.push(symbol);
|
|
103
|
-
identifierSymbols.set(node, symbol);
|
|
104
|
-
return symbol;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function lookupBinding(
|
|
108
|
-
scope: MutableScope,
|
|
109
|
-
name: string,
|
|
110
|
-
): Symbol | undefined {
|
|
111
|
-
for (let s: MutableScope | null = scope; s; s = s.parent) {
|
|
112
|
-
const found = s.bindings.get(name);
|
|
113
|
-
if (found) {
|
|
114
|
-
return found;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function lookupLabel(scope: MutableScope, name: string): Symbol | undefined {
|
|
121
|
-
for (let s: MutableScope | null = scope; s; s = s.parent) {
|
|
122
|
-
const found = s.labels.get(name);
|
|
123
|
-
if (found) {
|
|
124
|
-
return found;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return undefined;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function reference(scope: MutableScope, node: Parser.Identifier) {
|
|
131
|
-
const symbol = lookupBinding(scope, node.name);
|
|
132
|
-
if (symbol) {
|
|
133
|
-
symbol.references.push(node);
|
|
134
|
-
identifierSymbols.set(node, symbol);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
let binding = globals.get(node.name);
|
|
138
|
-
if (!binding) {
|
|
139
|
-
binding = { name: node.name, references: [] };
|
|
140
|
-
globals.set(node.name, binding);
|
|
141
|
-
}
|
|
142
|
-
binding.references.push(node);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ラベルはブロック内での宣言位置に関わらずブロック全体から参照できる
|
|
146
|
-
// (前方goto)ため、通常の宣言文と違い先読みで登録する。
|
|
147
|
-
function hoistLabels(body: Parser.Statement[], scope: MutableScope) {
|
|
148
|
-
body.forEach((statement) => {
|
|
149
|
-
if (statement.type === "LabelStatement") {
|
|
150
|
-
declareLabel(scope, statement.label);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function resolveBlock(body: Parser.Statement[], scope: MutableScope) {
|
|
156
|
-
hoistLabels(body, scope);
|
|
157
|
-
body.forEach((statement) => {
|
|
158
|
-
resolveStatement(statement, scope);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function resolveStatement(
|
|
163
|
-
statement: Parser.Statement,
|
|
164
|
-
scope: MutableScope,
|
|
165
|
-
): void {
|
|
166
|
-
switch (statement.type) {
|
|
167
|
-
case "LocalStatement":
|
|
168
|
-
// 初期化式は新しいローカルが宣言される前の束縛で解決する
|
|
169
|
-
// (`local x = x` の右辺は外側のxを指す)
|
|
170
|
-
statement.init.forEach((expr) => {
|
|
171
|
-
resolveExpression(expr, scope);
|
|
172
|
-
});
|
|
173
|
-
statement.variables.forEach((v) => declare(scope, v, "local"));
|
|
174
|
-
return;
|
|
175
|
-
case "AssignmentStatement":
|
|
176
|
-
statement.init.forEach((expr) => {
|
|
177
|
-
resolveExpression(expr, scope);
|
|
178
|
-
});
|
|
179
|
-
statement.variables.forEach((v) => {
|
|
180
|
-
if (v.type === "Identifier") {
|
|
181
|
-
reference(scope, v);
|
|
182
|
-
} else {
|
|
183
|
-
resolveExpression(v, scope);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
return;
|
|
187
|
-
case "CallStatement":
|
|
188
|
-
resolveExpression(statement.expression, scope);
|
|
189
|
-
return;
|
|
190
|
-
case "DoStatement": {
|
|
191
|
-
const inner = createScope("block", scope);
|
|
192
|
-
resolveBlock(statement.body, inner);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
case "WhileStatement": {
|
|
196
|
-
resolveExpression(statement.condition, scope);
|
|
197
|
-
const inner = createScope("block", scope);
|
|
198
|
-
resolveBlock(statement.body, inner);
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
case "RepeatStatement": {
|
|
202
|
-
// `until`の条件式は本体で宣言されたローカルを参照できる
|
|
203
|
-
const inner = createScope("block", scope);
|
|
204
|
-
resolveBlock(statement.body, inner);
|
|
205
|
-
resolveExpression(statement.condition, inner);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
case "IfStatement":
|
|
209
|
-
statement.clauses.forEach((clause) => {
|
|
210
|
-
if (clause.type !== "ElseClause") {
|
|
211
|
-
resolveExpression(clause.condition, scope);
|
|
212
|
-
}
|
|
213
|
-
const inner = createScope("block", scope);
|
|
214
|
-
resolveBlock(clause.body, inner);
|
|
215
|
-
});
|
|
216
|
-
return;
|
|
217
|
-
case "ForNumericStatement": {
|
|
218
|
-
resolveExpression(statement.start, scope);
|
|
219
|
-
resolveExpression(statement.end, scope);
|
|
220
|
-
if (statement.step) {
|
|
221
|
-
resolveExpression(statement.step, scope);
|
|
222
|
-
}
|
|
223
|
-
const inner = createScope("block", scope);
|
|
224
|
-
declare(inner, statement.variable, "for");
|
|
225
|
-
resolveBlock(statement.body, inner);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
case "ForGenericStatement": {
|
|
229
|
-
statement.iterators.forEach((iterator) => {
|
|
230
|
-
resolveExpression(iterator, scope);
|
|
231
|
-
});
|
|
232
|
-
const inner = createScope("block", scope);
|
|
233
|
-
statement.variables.forEach((v) => declare(inner, v, "for"));
|
|
234
|
-
resolveBlock(statement.body, inner);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
case "FunctionDeclaration":
|
|
238
|
-
resolveFunctionDeclaration(statement, scope);
|
|
239
|
-
return;
|
|
240
|
-
case "ReturnStatement":
|
|
241
|
-
statement.arguments.forEach((argument) => {
|
|
242
|
-
resolveExpression(argument, scope);
|
|
243
|
-
});
|
|
244
|
-
return;
|
|
245
|
-
case "BreakStatement":
|
|
246
|
-
return;
|
|
247
|
-
case "LabelStatement":
|
|
248
|
-
// hoistLabelsで宣言済みのため、ここでは何もしない
|
|
249
|
-
return;
|
|
250
|
-
case "GotoStatement": {
|
|
251
|
-
const symbol = lookupLabel(scope, statement.label.name);
|
|
252
|
-
if (symbol) {
|
|
253
|
-
symbol.references.push(statement.label);
|
|
254
|
-
identifierSymbols.set(statement.label, symbol);
|
|
255
|
-
}
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
default: {
|
|
259
|
-
const exhaustive: never = statement;
|
|
260
|
-
throw new TypeError(
|
|
261
|
-
"Unknown statement type: `" + JSON.stringify(exhaustive) + "`",
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function resolveFunctionDeclaration(
|
|
268
|
-
fn: Parser.FunctionDeclaration,
|
|
269
|
-
scope: MutableScope,
|
|
270
|
-
) {
|
|
271
|
-
if (fn.identifier) {
|
|
272
|
-
if (fn.identifier.type === "Identifier") {
|
|
273
|
-
if (fn.isLocal) {
|
|
274
|
-
// `local function`は再帰呼び出しのため、本体を解決する前に自身を宣言する
|
|
275
|
-
declare(scope, fn.identifier, "local");
|
|
276
|
-
} else {
|
|
277
|
-
// 非local: 既存のローカル/グローバルへの代入として扱う(新規宣言ではない)
|
|
278
|
-
reference(scope, fn.identifier);
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
281
|
-
resolveExpression(fn.identifier, scope);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
const inner = createScope("function", scope);
|
|
285
|
-
fn.parameters.forEach((parameter) => {
|
|
286
|
-
if (parameter.type === "Identifier") {
|
|
287
|
-
declare(inner, parameter, "param");
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
resolveBlock(fn.body, inner);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function resolveExpression(
|
|
294
|
-
expr: Parser.Expression,
|
|
295
|
-
scope: MutableScope,
|
|
296
|
-
): void {
|
|
297
|
-
switch (expr.type) {
|
|
298
|
-
case "Identifier":
|
|
299
|
-
reference(scope, expr);
|
|
300
|
-
return;
|
|
301
|
-
case "StringLiteral":
|
|
302
|
-
case "NumericLiteral":
|
|
303
|
-
case "BooleanLiteral":
|
|
304
|
-
case "NilLiteral":
|
|
305
|
-
case "VarargLiteral":
|
|
306
|
-
return;
|
|
307
|
-
case "LogicalExpression":
|
|
308
|
-
case "BinaryExpression":
|
|
309
|
-
resolveExpression(expr.left, scope);
|
|
310
|
-
resolveExpression(expr.right, scope);
|
|
311
|
-
return;
|
|
312
|
-
case "UnaryExpression":
|
|
313
|
-
resolveExpression(expr.argument, scope);
|
|
314
|
-
return;
|
|
315
|
-
case "CallExpression":
|
|
316
|
-
resolveExpression(expr.base, scope);
|
|
317
|
-
expr.arguments.forEach((argument) => {
|
|
318
|
-
resolveExpression(argument, scope);
|
|
319
|
-
});
|
|
320
|
-
return;
|
|
321
|
-
case "TableCallExpression":
|
|
322
|
-
resolveExpression(expr.base, scope);
|
|
323
|
-
resolveExpression(expr.arguments, scope);
|
|
324
|
-
return;
|
|
325
|
-
case "StringCallExpression":
|
|
326
|
-
resolveExpression(expr.base, scope);
|
|
327
|
-
resolveExpression(expr.argument, scope);
|
|
328
|
-
return;
|
|
329
|
-
case "IndexExpression":
|
|
330
|
-
resolveExpression(expr.base, scope);
|
|
331
|
-
resolveExpression(expr.index, scope);
|
|
332
|
-
return;
|
|
333
|
-
case "MemberExpression":
|
|
334
|
-
resolveExpression(expr.base, scope);
|
|
335
|
-
// フィールド名(`.identifier`)は変数参照ではないため解決しない
|
|
336
|
-
return;
|
|
337
|
-
case "FunctionDeclaration": {
|
|
338
|
-
const inner = createScope("function", scope);
|
|
339
|
-
expr.parameters.forEach((parameter) => {
|
|
340
|
-
if (parameter.type === "Identifier") {
|
|
341
|
-
declare(inner, parameter, "param");
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
resolveBlock(expr.body, inner);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
case "TableConstructorExpression":
|
|
348
|
-
expr.fields.forEach((field) => {
|
|
349
|
-
if (field.type === "TableKey") {
|
|
350
|
-
resolveExpression(field.key, scope);
|
|
351
|
-
resolveExpression(field.value, scope);
|
|
352
|
-
} else if (field.type === "TableValue") {
|
|
353
|
-
resolveExpression(field.value, scope);
|
|
354
|
-
} else {
|
|
355
|
-
// TableKeyString: キー名(`{ key = value }`のkey)は変数参照ではない
|
|
356
|
-
resolveExpression(field.value, scope);
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
return;
|
|
360
|
-
default: {
|
|
361
|
-
const exhaustive: never = expr;
|
|
362
|
-
throw new TypeError(
|
|
363
|
-
"Unknown expression type: `" + JSON.stringify(exhaustive) + "`",
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const chunkScope = createScope("chunk", null);
|
|
370
|
-
resolveBlock(chunk.body, chunkScope);
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
chunkScope,
|
|
374
|
-
symbols: allSymbols,
|
|
375
|
-
globals,
|
|
376
|
-
symbolOf: (identifier) => identifierSymbols.get(identifier),
|
|
377
|
-
};
|
|
378
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { Minifier } from "../src/minifier";
|
|
4
|
-
import { LUAPARSE_SETTINGS, fixtureEntryPath } from "./lib/helpers";
|
|
5
|
-
|
|
6
|
-
// require/dofileの参照グラフに循環がある場合、Linkパスがエラーを投げて
|
|
7
|
-
// 出力を開始しないことを検証する(#18)。
|
|
8
|
-
|
|
9
|
-
void test("circular require is rejected with a clear error", () => {
|
|
10
|
-
const minifier = new Minifier(
|
|
11
|
-
fixtureEntryPath("circular-require"),
|
|
12
|
-
LUAPARSE_SETTINGS,
|
|
13
|
-
{ moduleLikeLua: true },
|
|
14
|
-
);
|
|
15
|
-
assert.throws(
|
|
16
|
-
() => minifier.parse(),
|
|
17
|
-
/Circular require\/dofile detected: a -> b -> a/,
|
|
18
|
-
);
|
|
19
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
print("hello from mod")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
print("hello from greet")
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
local depAlpha = require("dep_alpha")
|
|
2
|
-
local depBravo = require("dep_bravo")
|
|
3
|
-
local depCharlie = require("dep_charlie")
|
|
4
|
-
local depDelta = require("dep_delta")
|
|
5
|
-
local depEcho = require("dep_echo")
|
|
6
|
-
local depFoxtrot = require("dep_foxtrot")
|
|
7
|
-
local depGolf = require("dep_golf")
|
|
8
|
-
local depHotel = require("dep_hotel")
|
|
9
|
-
local depIndia = require("dep_india")
|
|
10
|
-
local depJuliet = require("dep_juliet")
|
|
11
|
-
local depKilo = require("dep_kilo")
|
|
12
|
-
|
|
13
|
-
print(
|
|
14
|
-
depAlpha,
|
|
15
|
-
depBravo,
|
|
16
|
-
depCharlie,
|
|
17
|
-
depDelta,
|
|
18
|
-
depEcho,
|
|
19
|
-
depFoxtrot,
|
|
20
|
-
depGolf,
|
|
21
|
-
depHotel,
|
|
22
|
-
depIndia,
|
|
23
|
-
depJuliet,
|
|
24
|
-
depKilo
|
|
25
|
-
)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
return { value = 42 }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
return { value = 1 }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
print(require("mod").hello())
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
return { hello = function() return "hello" end }
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { WORKING_CASES, KNOWN_BUG_CASES, runMinifier } from "./lib/helpers";
|
|
4
|
-
import { findIdentifierCollisions } from "./lib/collision";
|
|
5
|
-
|
|
6
|
-
// 出力コードの同一スコープ内で、同じ短縮識別子が異なるオリジナル識別子に
|
|
7
|
-
// 割り当てられていないことを検証する(#12の回帰防止)。
|
|
8
|
-
|
|
9
|
-
for (const c of WORKING_CASES) {
|
|
10
|
-
void test(`identifier collision: ${c.label}`, async () => {
|
|
11
|
-
const { code, map } = runMinifier(c);
|
|
12
|
-
const collisions = await findIdentifierCollisions(code, map);
|
|
13
|
-
assert.deepEqual(collisions, []);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
for (const c of KNOWN_BUG_CASES) {
|
|
18
|
-
const issue = String(c.issue);
|
|
19
|
-
void test(
|
|
20
|
-
`identifier collision (known bug, issue #${issue}): ${c.label}`,
|
|
21
|
-
{ todo: `#${issue} の本修正待ち` },
|
|
22
|
-
async () => {
|
|
23
|
-
const { code, map } = runMinifier(c);
|
|
24
|
-
const collisions = await findIdentifierCollisions(code, map);
|
|
25
|
-
assert.deepEqual(collisions, []);
|
|
26
|
-
},
|
|
27
|
-
);
|
|
28
|
-
}
|