Skip to content

Commit ac89091

Browse files
fix(template-compiler): relax attribute name restriction on usage of hyphen and underscore in combination @W-12021741 (#3143)
* feat: relax restriction on usage of hyphen and underscore in combination @W-12021741 * test: more tests * test: add tests for emoji
1 parent a4e1c8f commit ac89091

File tree

19 files changed

+907
-17
lines changed

19 files changed

+907
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
<!-- These test cases are important because a hyphen(-) in attribute name indicates that the
2+
next character should be uppercased(https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_props_names)-->
13
<template>
2-
<!-- attribute name with underscore + hyphen "_-" combination -->
3-
<x-button under_-hyphen="bar"></x-button>
4-
54
<!-- attribute name with hyphen + underscore "-_" combination -->
65
<x-button under-_hyphen="bar"></x-button>
76
</template>

packages/@lwc/template-compiler/src/__tests__/fixtures/attributes/invalid-error-hyphen-underscore/metadata.json

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
{
22
"warnings": [
3-
{
4-
"code": 1126,
5-
"message": "LWC1126: under_-hyphen is not valid attribute for x-button. Attribute name cannot contain combination of underscore and special characters.",
6-
"level": 1,
7-
"location": {
8-
"line": 3,
9-
"column": 15,
10-
"start": 95,
11-
"length": 19
12-
}
13-
},
143
{
154
"code": 1126,
165
"message": "LWC1126: under-_hyphen is not valid attribute for x-button. Attribute name cannot contain combination of underscore and special characters.",
176
"level": 1,
187
"location": {
19-
"line": 6,
8+
"line": 5,
209
"column": 15,
21-
"start": 212,
10+
"start": 328,
2211
"length": 19
2312
}
2413
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- These test cases are important because a hyphen(-) in attribute name indicates that the
2+
next character should be uppercased(https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_props_names)-->
3+
<template>
4+
<!-- invalid: trailing hyphen-->
5+
<x-button hyphen-="bar"></x-button>
6+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/@lwc/template-compiler/src/__tests__/fixtures/attributes/invalid-hyphen-attribute/expected.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"warnings": [
3+
{
4+
"code": 1125,
5+
"message": "LWC1125: hyphen- is not valid attribute for x-button. Attribute name must end with alpha-numeric character.",
6+
"level": 1,
7+
"location": {
8+
"line": 5,
9+
"column": 15,
10+
"start": 295,
11+
"length": 13
12+
}
13+
}
14+
]
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<template>
2+
<!-- These are valid javascript propery names but their usage is restricted by template-compiler
3+
This test case is to just document the existing precedent-->
4+
5+
<!-- leading latin characters-->
6+
<x-button ñana="nana"></x-button>
7+
8+
<!-- trailing latin characters-->
9+
<x-button nanå="nana"></x-button>
10+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/@lwc/template-compiler/src/__tests__/fixtures/attributes/invalid-non-alphanumeric/expected.js

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"warnings": [
3+
{
4+
"code": 1124,
5+
"message": "LWC1124: ñana is not valid attribute for x-button. Attribute name must start with alphabetic character or a hyphen.",
6+
"level": 1,
7+
"location": {
8+
"line": 6,
9+
"column": 15,
10+
"start": 233,
11+
"length": 11
12+
}
13+
},
14+
{
15+
"code": 1125,
16+
"message": "LWC1125: nanå is not valid attribute for x-button. Attribute name must end with alpha-numeric character.",
17+
"level": 1,
18+
"location": {
19+
"line": 9,
20+
"column": 15,
21+
"start": 310,
22+
"length": 11
23+
}
24+
}
25+
]
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!-- These test cases are important because a hyphen(-) in attribute name indicates that the
2+
next character should be uppercased(https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_props_names)-->
3+
<template>
4+
<!-- attribute name with underscore followed by hyphen "_-" combination -->
5+
6+
<!-- under_-hyphen: translates to under_Hyphen class property-->
7+
<x-button under_-hyphen="bar"></x-button>
8+
9+
<!-- pacal case represented by hyphens: translates to PascalCase class property -->
10+
<x-button -pascal-case="bar"></x-button>
11+
12+
<!-- leading hyphen: translated to Hyphen class property-->
13+
<x-button -hyphen="bar"></x-button>
14+
15+
<!-- valid: hyphen followed by numeric character-->
16+
<x-button hyphen-3pecial="bar"></x-button>
17+
18+
<!-- valid: hyphen followed by latin lower case character-->
19+
<x-button hyphen-ßpecial="bar"></x-button>
20+
21+
<!-- valid: hyphen followed by latin lower case character-->
22+
<x-button hyphen-àpecial="bar"></x-button>
23+
24+
<!-- valid: hyphen followed by latin lower case character-->
25+
<x-button hyphen-ªpecial="bar"></x-button>
26+
27+
<!-- valid: hyphen followed by emoji character-->
28+
<x-button hyphen-🎉pecial="bar"></x-button>
29+
<x-button hyphen-🇺🇸pecial="bar"></x-button>
30+
</template>

0 commit comments

Comments
 (0)