@angular-wave/angular.ts 0.4.1 → 0.4.3
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/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +7 -7
- package/src/angular.spec.js +1 -264
- package/src/animations/animate-css-driver.js +2 -2
- package/src/animations/animate-css.js +7 -8
- package/src/animations/animate-js-driver.js +1 -3
- package/src/animations/animate-js.js +4 -4
- package/src/animations/animate-queue.js +6 -6
- package/src/animations/animation.js +3 -3
- package/src/animations/shared.js +16 -14
- package/src/core/compile/attributes.js +2 -3
- package/src/core/compile/compile.js +248 -232
- package/src/core/compile/compile.spec.js +46 -51
- package/src/core/compile/compile.test.js +1 -1
- package/src/core/interpolate/interpolate.js +2 -2
- package/src/core/interval/interval.test.js +1 -1
- package/src/core/{parser/lexer.html → parse/ast/ast.html} +1 -1
- package/src/core/{parser → parse/ast}/ast.js +43 -29
- package/src/core/parse/ast/ast.spec.js +1462 -0
- package/src/core/parse/ast/ast.test.js +10 -0
- package/src/core/{parser → parse}/interpreter.js +10 -10
- package/src/core/parse/lexer/lexer.html +18 -0
- package/src/core/{parser → parse/lexer}/lexer.js +1 -1
- package/src/core/{parser → parse/lexer}/lexer.spec.js +2 -2
- package/src/core/parse/lexer/lexer.test.js +10 -0
- package/src/core/{parser → parse}/parse.html +1 -1
- package/src/core/{parser → parse}/parse.js +6 -6
- package/src/core/{parser → parse}/parse.spec.js +6 -1725
- package/src/core/parse/parse.test.js +10 -0
- package/src/core/parse/parser/parser.html +18 -0
- package/src/core/{parser → parse/parser}/parser.js +6 -6
- package/src/core/parse/parser/parser.spec.js +8 -0
- package/src/core/parse/parser/parser.test.js +10 -0
- package/src/core/sce/sce.js +1 -2
- package/src/core/scope/scope.js +4 -5
- package/src/directive/attrs/attrs.test.js +11 -0
- package/src/directive/attrs/boolean.html +18 -0
- package/src/directive/attrs/boolean.test.js +11 -0
- package/src/directive/attrs/element-style.html +21 -0
- package/src/directive/attrs/element-style.test.js +11 -0
- package/src/directive/bind/bing-html.spec.js +1 -1
- package/src/directive/class/class.js +1 -1
- package/src/directive/form/form.js +12 -19
- package/src/directive/if/if.spec.js +2 -3
- package/src/directive/if/if.test.js +1 -2
- package/src/directive/include/include.js +2 -2
- package/src/directive/input/input.js +1 -2
- package/src/directive/input/input.spec.js +187 -191
- package/src/directive/list/list.js +2 -2
- package/src/directive/model/model.js +14 -19
- package/src/directive/model-options/model-options.js +22 -26
- package/src/directive/options/options.js +1 -3
- package/src/directive/options/options.spec.js +3 -4
- package/src/directive/repeat/repeat.js +2 -2
- package/src/directive/repeat/repeat.spec.js +48 -57
- package/src/directive/select/select.spec.js +9 -10
- package/src/directive/switch/switch.js +1 -2
- package/src/directive/validators/validators.js +3 -3
- package/src/public.js +1 -1
- package/src/router/directives/state-directives.js +18 -16
- package/src/router/directives/view-directive.js +2 -2
- package/src/router/state/views.js +2 -2
- package/src/router/url/url-service.js +2 -8
- package/src/router/url/url-service.spec.js +3 -4
- package/src/services/http/http.js +5 -6
- package/src/services/http-backend/http-backend.js +19 -17
- package/src/shared/common.js +5 -8
- package/src/shared/jqlite/jqlite.js +14 -12
- package/src/shared/jqlite/jqlite.spec.js +2 -2
- package/src/shared/utils.js +15 -92
- package/types/animations/shared.d.ts +1 -1
- package/types/core/compile/compile.d.ts +1 -1
- package/types/core/interpolate/interpolate.d.ts +1 -1
- package/types/core/{parser → parse/ast}/ast.d.ts +17 -17
- package/types/core/{parser → parse}/interpreter.d.ts +7 -7
- package/types/core/{parser → parse/parser}/parser.d.ts +8 -8
- package/types/core/scope/scope.d.ts +3 -3
- package/types/directive/class/class.d.ts +3 -3
- package/types/directive/form/form.d.ts +1 -0
- package/types/directive/model/model.d.ts +6 -6
- package/types/directive/validators/validators.d.ts +3 -3
- package/types/shared/common.d.ts +0 -1
- package/types/shared/utils.d.ts +0 -35
- package/src/core/parser/parser.test.js +0 -19
- /package/src/core/{parser → parse}/ast-type.js +0 -0
- /package/src/core/{parser → parse}/parse.md +0 -0
- /package/types/core/{parser → parse}/ast-type.d.ts +0 -0
- /package/types/core/{parser → parse/lexer}/lexer.d.ts +0 -0
- /package/types/core/{parser → parse}/parse.d.ts +0 -0
|
@@ -2,7 +2,6 @@ import { Angular } from "../../loader";
|
|
|
2
2
|
import { createInjector } from "../di/injector";
|
|
3
3
|
import { dealoc, JQLite, getOrSetCacheData } from "../../shared/jqlite/jqlite";
|
|
4
4
|
import {
|
|
5
|
-
forEach,
|
|
6
5
|
isFunction,
|
|
7
6
|
valueFn,
|
|
8
7
|
isElement,
|
|
@@ -435,42 +434,36 @@ describe("$compile", () => {
|
|
|
435
434
|
expect(el.data("hasCompiled")).toBe(true);
|
|
436
435
|
});
|
|
437
436
|
|
|
438
|
-
|
|
439
|
-
{
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
});
|
|
464
|
-
reloadModules();
|
|
465
|
-
$compile(dom);
|
|
466
|
-
expect(hasCompiled).toBe(expected[type]);
|
|
467
|
-
},
|
|
468
|
-
);
|
|
437
|
+
Object.entries({
|
|
438
|
+
E: { element: true, attribute: false },
|
|
439
|
+
A: { element: false, attribute: true },
|
|
440
|
+
EA: { element: true, attribute: true },
|
|
441
|
+
}).forEach(([restrict, expected]) => {
|
|
442
|
+
describe("restricted to " + restrict, () => {
|
|
443
|
+
Object.entries({
|
|
444
|
+
element: "<my-directive></my-directive>",
|
|
445
|
+
attribute: "<div my-directive></div>",
|
|
446
|
+
}).forEach(([type, dom]) => {
|
|
447
|
+
it(
|
|
448
|
+
(expected[type] ? "matches" : "does not match") + " on " + type,
|
|
449
|
+
() => {
|
|
450
|
+
var hasCompiled = false;
|
|
451
|
+
myModule.directive("myDirective", () => {
|
|
452
|
+
return {
|
|
453
|
+
restrict: restrict,
|
|
454
|
+
compile: () => {
|
|
455
|
+
hasCompiled = true;
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
});
|
|
459
|
+
reloadModules();
|
|
460
|
+
$compile(dom);
|
|
461
|
+
expect(hasCompiled).toBe(expected[type]);
|
|
469
462
|
},
|
|
470
463
|
);
|
|
471
464
|
});
|
|
472
|
-
}
|
|
473
|
-
);
|
|
465
|
+
});
|
|
466
|
+
});
|
|
474
467
|
|
|
475
468
|
it("applies to attributes when no restrict given", () => {
|
|
476
469
|
var hasCompiled = false;
|
|
@@ -5182,14 +5175,16 @@ describe("$compile", () => {
|
|
|
5182
5175
|
|
|
5183
5176
|
describe("restrict", () => {
|
|
5184
5177
|
it("should allow restriction of availability", () => {
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5178
|
+
Object.entries({ div: "E", attr: "A", all: "EA" }).forEach(
|
|
5179
|
+
([name, restrict]) => {
|
|
5180
|
+
myModule.directive(name, () => ({
|
|
5181
|
+
restrict,
|
|
5182
|
+
compile: valueFn((scope, element, attr) => {
|
|
5183
|
+
log.push(name);
|
|
5184
|
+
}),
|
|
5185
|
+
}));
|
|
5186
|
+
},
|
|
5187
|
+
);
|
|
5193
5188
|
|
|
5194
5189
|
reloadModules();
|
|
5195
5190
|
dealoc($compile('<span div class="div"></span>')($rootScope));
|
|
@@ -11332,9 +11327,9 @@ describe("$compile", () => {
|
|
|
11332
11327
|
},
|
|
11333
11328
|
];
|
|
11334
11329
|
|
|
11335
|
-
forEach(
|
|
11336
|
-
|
|
11337
|
-
|
|
11330
|
+
controllerOptions.forEach((controllerOption) => {
|
|
11331
|
+
Object.values(scopeOptions).forEach((scopeOption) => {
|
|
11332
|
+
Object.values(templateOptions).forEach((templateOption) => {
|
|
11338
11333
|
const description = [];
|
|
11339
11334
|
const ddo = {
|
|
11340
11335
|
bindToController: {
|
|
@@ -11345,8 +11340,7 @@ describe("$compile", () => {
|
|
|
11345
11340
|
},
|
|
11346
11341
|
};
|
|
11347
11342
|
|
|
11348
|
-
forEach(
|
|
11349
|
-
[controllerOption, scopeOption, templateOption],
|
|
11343
|
+
[controllerOption, scopeOption, templateOption].forEach(
|
|
11350
11344
|
(option) => {
|
|
11351
11345
|
description.push(option.description);
|
|
11352
11346
|
delete option.description;
|
|
@@ -15924,7 +15918,7 @@ describe("$compile", () => {
|
|
|
15924
15918
|
"http://example.com/image1.jpg?x=a2x,b 1x,http://example.com/ima,ge2.jpg 2x",
|
|
15925
15919
|
};
|
|
15926
15920
|
|
|
15927
|
-
forEach(
|
|
15921
|
+
Object.entries(testSet).forEach(([url, ref]) => {
|
|
15928
15922
|
$rootScope.testUrl = url;
|
|
15929
15923
|
$rootScope.$digest();
|
|
15930
15924
|
expect(element.attr("srcset")).toEqual(ref);
|
|
@@ -17257,7 +17251,7 @@ describe("$compile", () => {
|
|
|
17257
17251
|
const toCompile = JQLite(template);
|
|
17258
17252
|
|
|
17259
17253
|
const preCompiledChildren = getAll(toCompile);
|
|
17260
|
-
forEach(
|
|
17254
|
+
Object.entries(preCompiledChildren).forEach(([i, element]) => {
|
|
17261
17255
|
getOrSetCacheData(element, "foo", `template#${i}`);
|
|
17262
17256
|
});
|
|
17263
17257
|
|
|
@@ -17265,10 +17259,11 @@ describe("$compile", () => {
|
|
|
17265
17259
|
$rootScope.$apply();
|
|
17266
17260
|
linkedElements.remove();
|
|
17267
17261
|
|
|
17268
|
-
forEach(
|
|
17262
|
+
Object.entries(preCompiledChildren).forEach(([i, element]) => {
|
|
17269
17263
|
expect(CACHE.has(element[EXPANDO])).toBe(false, `template#${i}`);
|
|
17270
17264
|
});
|
|
17271
|
-
|
|
17265
|
+
|
|
17266
|
+
Object.entries(linkedElements).forEach(([i, element]) => {
|
|
17272
17267
|
expect(CACHE.has(element[EXPANDO])).toBe(false, `linked#${i}`);
|
|
17273
17268
|
});
|
|
17274
17269
|
}
|
|
@@ -5,7 +5,7 @@ const TEST_URL = "src/core/compile/compile.html?random=false";
|
|
|
5
5
|
test("unit tests contain no errors", async ({ page }) => {
|
|
6
6
|
await page.goto(TEST_URL);
|
|
7
7
|
await page.content();
|
|
8
|
-
await page.waitForTimeout(
|
|
8
|
+
await page.waitForTimeout(1000);
|
|
9
9
|
await expect(page.locator(".jasmine-overall-result")).toHaveText(
|
|
10
10
|
/0 failures/,
|
|
11
11
|
);
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
valueFn,
|
|
7
7
|
extend,
|
|
8
8
|
} from "../../shared/utils";
|
|
9
|
-
import { constantWatchDelegate } from "../
|
|
9
|
+
import { constantWatchDelegate } from "../parse/parse.js";
|
|
10
10
|
|
|
11
11
|
const $interpolateMinErr = minErr("$interpolate");
|
|
12
12
|
function throwNoconcat(text) {
|
|
@@ -81,7 +81,7 @@ export class InterpolateProvider {
|
|
|
81
81
|
"$sce",
|
|
82
82
|
/**
|
|
83
83
|
*
|
|
84
|
-
* @param {import("../
|
|
84
|
+
* @param {import("../parse/parse").ParseService} $parse
|
|
85
85
|
* @param {*} $sce
|
|
86
86
|
* @returns
|
|
87
87
|
*/
|
|
@@ -5,7 +5,7 @@ const TEST_URL = "src/core/interval/interval.html";
|
|
|
5
5
|
test("unit tests contain no errors", async ({ page }) => {
|
|
6
6
|
await page.goto(TEST_URL);
|
|
7
7
|
await page.content();
|
|
8
|
-
await page.waitForTimeout(
|
|
8
|
+
await page.waitForTimeout(500);
|
|
9
9
|
await expect(page.locator(".jasmine-overall-result")).toHaveText(
|
|
10
10
|
/0 failures/,
|
|
11
11
|
);
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<script src="/jasmine/jasmine-5.1.2/jasmine-html.js"></script>
|
|
11
11
|
<script src="/jasmine/jasmine-5.1.2/boot0.js"></script>
|
|
12
12
|
<script src="/jasmine/jasmine-5.1.2/boot1.js"></script>
|
|
13
|
-
<script type="module" src="/src/core/
|
|
13
|
+
<script type="module" src="/src/core/parse/ast/ast.spec.js"></script>
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="dummy"></div>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isAssignable } from "
|
|
2
|
-
import { ASTType } from "
|
|
3
|
-
import { minErr } from "
|
|
1
|
+
import { isAssignable } from "../interpreter.js";
|
|
2
|
+
import { ASTType } from "../ast-type.js";
|
|
3
|
+
import { minErr } from "../../../shared/utils.js";
|
|
4
4
|
|
|
5
5
|
const $parseMinErr = minErr("$parse");
|
|
6
6
|
|
|
@@ -48,10 +48,10 @@ export const literals = new Map(
|
|
|
48
48
|
*/
|
|
49
49
|
export class AST {
|
|
50
50
|
/**
|
|
51
|
-
* @param {import('
|
|
51
|
+
* @param {import('../lexer/lexer.js').Lexer} lexer - The lexer instance for tokenizing input
|
|
52
52
|
*/
|
|
53
53
|
constructor(lexer) {
|
|
54
|
-
/** @type {import('
|
|
54
|
+
/** @type {import('../lexer/lexer.js').Lexer} */
|
|
55
55
|
this.lexer = lexer;
|
|
56
56
|
this.selfReferential = {
|
|
57
57
|
this: { type: ASTType.ThisExpression },
|
|
@@ -202,7 +202,7 @@ export class AST {
|
|
|
202
202
|
while ((token = this.expect("==", "!=", "===", "!=="))) {
|
|
203
203
|
left = {
|
|
204
204
|
type: ASTType.BinaryExpression,
|
|
205
|
-
operator: /** @type {import("
|
|
205
|
+
operator: /** @type {import("../lexer/lexer.js").Token} */ (token).text,
|
|
206
206
|
left,
|
|
207
207
|
right: this.relational(),
|
|
208
208
|
};
|
|
@@ -220,7 +220,7 @@ export class AST {
|
|
|
220
220
|
while ((token = this.expect("<", ">", "<=", ">="))) {
|
|
221
221
|
left = {
|
|
222
222
|
type: ASTType.BinaryExpression,
|
|
223
|
-
operator: /** @type {import("
|
|
223
|
+
operator: /** @type {import("../lexer/lexer.js").Token} */ (token).text,
|
|
224
224
|
left,
|
|
225
225
|
right: this.additive(),
|
|
226
226
|
};
|
|
@@ -238,7 +238,7 @@ export class AST {
|
|
|
238
238
|
while ((token = this.expect("+", "-"))) {
|
|
239
239
|
left = {
|
|
240
240
|
type: ASTType.BinaryExpression,
|
|
241
|
-
operator: /** @type {import("
|
|
241
|
+
operator: /** @type {import("../lexer/lexer.js").Token} */ (token).text,
|
|
242
242
|
left,
|
|
243
243
|
right: this.multiplicative(),
|
|
244
244
|
};
|
|
@@ -256,7 +256,7 @@ export class AST {
|
|
|
256
256
|
while ((token = this.expect("*", "/", "%"))) {
|
|
257
257
|
left = {
|
|
258
258
|
type: ASTType.BinaryExpression,
|
|
259
|
-
operator: /** @type {import("
|
|
259
|
+
operator: /** @type {import("../lexer/lexer.js").Token} */ (token).text,
|
|
260
260
|
left,
|
|
261
261
|
right: this.unary(),
|
|
262
262
|
};
|
|
@@ -273,7 +273,7 @@ export class AST {
|
|
|
273
273
|
if ((token = this.expect("+", "-", "!"))) {
|
|
274
274
|
return {
|
|
275
275
|
type: ASTType.UnaryExpression,
|
|
276
|
-
operator: /** @type {import("
|
|
276
|
+
operator: /** @type {import("../lexer/lexer.js").Token} */ (token).text,
|
|
277
277
|
prefix: true,
|
|
278
278
|
argument: this.unary(),
|
|
279
279
|
};
|
|
@@ -297,40 +297,48 @@ export class AST {
|
|
|
297
297
|
} else if (
|
|
298
298
|
Object.prototype.hasOwnProperty.call(
|
|
299
299
|
this.selfReferential,
|
|
300
|
-
/** @type {import("
|
|
300
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek()).text,
|
|
301
301
|
)
|
|
302
302
|
) {
|
|
303
303
|
primary = structuredClone(this.selfReferential[this.consume().text]);
|
|
304
304
|
} else if (
|
|
305
|
-
literals.has(
|
|
305
|
+
literals.has(
|
|
306
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek()).text,
|
|
307
|
+
)
|
|
306
308
|
) {
|
|
307
309
|
primary = {
|
|
308
310
|
type: ASTType.Literal,
|
|
309
311
|
value: literals.get(this.consume().text),
|
|
310
312
|
};
|
|
311
313
|
} else if (
|
|
312
|
-
/** @type {import("
|
|
314
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek()).identifier
|
|
313
315
|
) {
|
|
314
316
|
primary = this.identifier();
|
|
315
|
-
} else if (
|
|
317
|
+
} else if (
|
|
318
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek()).constant
|
|
319
|
+
) {
|
|
316
320
|
primary = this.constant();
|
|
317
321
|
} else {
|
|
318
322
|
this.throwError(
|
|
319
323
|
"not a primary expression",
|
|
320
|
-
/** @type {import("
|
|
324
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek()),
|
|
321
325
|
);
|
|
322
326
|
}
|
|
323
327
|
|
|
324
328
|
let next;
|
|
325
329
|
while ((next = this.expect("(", "[", "."))) {
|
|
326
|
-
if (
|
|
330
|
+
if (
|
|
331
|
+
/** @type {import("../lexer/lexer.js").Token} */ (next).text === "("
|
|
332
|
+
) {
|
|
327
333
|
primary = {
|
|
328
334
|
type: ASTType.CallExpression,
|
|
329
335
|
callee: primary,
|
|
330
336
|
arguments: this.parseArguments(),
|
|
331
337
|
};
|
|
332
338
|
this.consume(")");
|
|
333
|
-
} else if (
|
|
339
|
+
} else if (
|
|
340
|
+
/** @type {import("../lexer/lexer.js").Token} */ (next).text === "["
|
|
341
|
+
) {
|
|
334
342
|
primary = {
|
|
335
343
|
type: ASTType.MemberExpression,
|
|
336
344
|
object: primary,
|
|
@@ -338,7 +346,9 @@ export class AST {
|
|
|
338
346
|
computed: true,
|
|
339
347
|
};
|
|
340
348
|
this.consume("]");
|
|
341
|
-
} else if (
|
|
349
|
+
} else if (
|
|
350
|
+
/** @type {import("../lexer/lexer.js").Token} */ (next).text === "."
|
|
351
|
+
) {
|
|
342
352
|
primary = {
|
|
343
353
|
type: ASTType.MemberExpression,
|
|
344
354
|
object: primary,
|
|
@@ -447,13 +457,17 @@ export class AST {
|
|
|
447
457
|
break;
|
|
448
458
|
}
|
|
449
459
|
property = { type: ASTType.Property, kind: "init" };
|
|
450
|
-
if (
|
|
460
|
+
if (
|
|
461
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek())
|
|
462
|
+
.constant
|
|
463
|
+
) {
|
|
451
464
|
property.key = this.constant();
|
|
452
465
|
property.computed = false;
|
|
453
466
|
this.consume(":");
|
|
454
467
|
property.value = this.assignment();
|
|
455
468
|
} else if (
|
|
456
|
-
/** @type {import("
|
|
469
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek())
|
|
470
|
+
.identifier
|
|
457
471
|
) {
|
|
458
472
|
property.key = this.identifier();
|
|
459
473
|
property.computed = false;
|
|
@@ -473,7 +487,7 @@ export class AST {
|
|
|
473
487
|
} else {
|
|
474
488
|
this.throwError(
|
|
475
489
|
"invalid key",
|
|
476
|
-
/** @type {import("
|
|
490
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek()),
|
|
477
491
|
);
|
|
478
492
|
}
|
|
479
493
|
properties.push(property);
|
|
@@ -487,7 +501,7 @@ export class AST {
|
|
|
487
501
|
/**
|
|
488
502
|
* Throws a syntax error.
|
|
489
503
|
* @param {string} msg - The error message.
|
|
490
|
-
* @param {import("
|
|
504
|
+
* @param {import("../lexer/lexer.js").Token} [token] - The token that caused the error.
|
|
491
505
|
*/
|
|
492
506
|
throwError(msg, token) {
|
|
493
507
|
throw $parseMinErr(
|
|
@@ -504,7 +518,7 @@ export class AST {
|
|
|
504
518
|
/**
|
|
505
519
|
* Consumes a token if it matches the expected type.
|
|
506
520
|
* @param {string} [e1] - The expected token type.
|
|
507
|
-
* @returns {import("
|
|
521
|
+
* @returns {import("../lexer/lexer.js").Token} The consumed token.
|
|
508
522
|
*/
|
|
509
523
|
consume(e1) {
|
|
510
524
|
if (this.tokens.length === 0) {
|
|
@@ -519,16 +533,16 @@ export class AST {
|
|
|
519
533
|
if (!token) {
|
|
520
534
|
this.throwError(
|
|
521
535
|
`is unexpected, expecting [${e1}]`,
|
|
522
|
-
/** @type {import("
|
|
536
|
+
/** @type {import("../lexer/lexer.js").Token} */ (this.peek()),
|
|
523
537
|
);
|
|
524
538
|
} else {
|
|
525
|
-
return /** @type {import("
|
|
539
|
+
return /** @type {import("../lexer/lexer.js").Token} */ (token);
|
|
526
540
|
}
|
|
527
541
|
}
|
|
528
542
|
|
|
529
543
|
/**
|
|
530
544
|
* Returns the next token without consuming it.
|
|
531
|
-
* @returns {import("
|
|
545
|
+
* @returns {import("../lexer/lexer.js").Token} The next token.
|
|
532
546
|
*/
|
|
533
547
|
peekToken() {
|
|
534
548
|
if (this.tokens.length === 0) {
|
|
@@ -544,7 +558,7 @@ export class AST {
|
|
|
544
558
|
/**
|
|
545
559
|
* Checks if the next token matches any of the expected types.
|
|
546
560
|
* @param {...string} [expected] - The expected token types.
|
|
547
|
-
* @returns {import('
|
|
561
|
+
* @returns {import('../lexer/lexer.js').Token|boolean} The next token if it matches, otherwise false.
|
|
548
562
|
*/
|
|
549
563
|
peek(...expected) {
|
|
550
564
|
return this.peekAhead(0, ...expected);
|
|
@@ -554,7 +568,7 @@ export class AST {
|
|
|
554
568
|
* Checks if the token at the specified index matches any of the expected types.
|
|
555
569
|
* @param {number} i - The index to check.
|
|
556
570
|
* @param {...string} [expected] - The expected token types.
|
|
557
|
-
* @returns {import("
|
|
571
|
+
* @returns {import("../lexer/lexer.js").Token|boolean} The token at the specified index if it matches, otherwise false.
|
|
558
572
|
*/
|
|
559
573
|
peekAhead(i, ...expected) {
|
|
560
574
|
if (this.tokens.length > i) {
|
|
@@ -573,7 +587,7 @@ export class AST {
|
|
|
573
587
|
/**
|
|
574
588
|
* Consumes the next token if it matches any of the expected types.
|
|
575
589
|
* @param {...string} [expected] - The expected token types.
|
|
576
|
-
* @returns {import("
|
|
590
|
+
* @returns {import("../lexer/lexer.js").Token|boolean} The consumed token if it matches, otherwise false.
|
|
577
591
|
*/
|
|
578
592
|
expect(...expected) {
|
|
579
593
|
const token = this.peek(...expected);
|