豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 660cc9f

Browse files
authored
fix: trait alias with no visibility and no alias now raises an error (#1230)
1 parent a7d9c1d commit 660cc9f

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/parser/class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ module.exports = {
725725
const name = this.text();
726726
this.next();
727727
alias = alias(name);
728-
} else if (flags === false) {
728+
} else if (flags === null) {
729729
// no visibility flags and no name => too bad
730730
this.expect(this.tok.T_STRING);
731731
}

test/snapshot/__snapshots__/trait.test.js.snap

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,57 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3+
exports[`trait trait alias with no visibility and no alias raises an error 1`] = `
4+
Program {
5+
"children": [
6+
Class {
7+
"attrGroups": [],
8+
"body": [
9+
TraitUse {
10+
"adaptations": [
11+
TraitAlias {
12+
"as": null,
13+
"kind": "traitalias",
14+
"method": "foo",
15+
"trait": null,
16+
"visibility": "",
17+
},
18+
],
19+
"kind": "traituse",
20+
"traits": [
21+
Name {
22+
"kind": "name",
23+
"name": "Foo",
24+
"resolution": "uqn",
25+
},
26+
],
27+
},
28+
],
29+
"extends": null,
30+
"implements": null,
31+
"isAbstract": false,
32+
"isAnonymous": false,
33+
"isFinal": false,
34+
"isReadonly": false,
35+
"kind": "class",
36+
"name": Identifier {
37+
"kind": "identifier",
38+
"name": "A",
39+
},
40+
},
41+
],
42+
"errors": [
43+
Error {
44+
"expected": 105,
45+
"kind": "error",
46+
"line": 1,
47+
"message": "Parse Error : syntax error, unexpected ';', expecting T_STRING on line 1",
48+
"token": "';'",
49+
},
50+
],
51+
"kind": "program",
52+
}
53+
`;
54+
355
exports[`trait trait name as identifier 1`] = `
456
Program {
557
"children": [

test/snapshot/trait.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ describe("trait", function () {
44
it("trait name as identifier", function () {
55
expect(parser.parseEval("trait A {}")).toMatchSnapshot();
66
});
7+
8+
it("trait alias with no visibility and no alias raises an error", function () {
9+
const test = parser.create({ parser: { suppressErrors: true } });
10+
expect(test.parseEval("class A { use Foo { foo as; } }")).toMatchSnapshot();
11+
});
712
});

0 commit comments

Comments
 (0)