-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(template-compiler): support leading hyphen in attr name (#1687)
* feat(template-compiler): support leading hyphen in attr name
- Loading branch information
Showing
17 changed files
with
114 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
.../@lwc/template-compiler/src/__tests__/fixtures/attributes/attribute-uppercase/actual.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<x-button | ||
-class="r" | ||
-data-xx="foo" | ||
-aria-hidden="hidden" | ||
-role="xx" | ||
-foo-bar="x" | ||
--foo-zaz="z" | ||
-foo_bar_baz="baz" | ||
></x-button> | ||
</template> |
29 changes: 29 additions & 0 deletions
29
.../@lwc/template-compiler/src/__tests__/fixtures/attributes/attribute-uppercase/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import _xButton from 'x/button'; | ||
import { registerTemplate } from 'lwc'; | ||
|
||
function tmpl($api, $cmp, $slotset, $ctx) { | ||
const { c: api_custom_element } = $api; | ||
return [ | ||
api_custom_element( | ||
'x-button', | ||
_xButton, | ||
{ | ||
props: { | ||
Class: 'r', | ||
DataXx: 'foo', | ||
AriaHidden: 'hidden', | ||
Role: 'xx', | ||
FooBar: 'x', | ||
FooZaz: 'z', | ||
Foo_bar_baz: 'baz' | ||
}, | ||
key: 0 | ||
}, | ||
[] | ||
|
||
), | ||
]; | ||
} | ||
|
||
export default registerTemplate(tmpl); | ||
tmpl.stylesheets = []; |
3 changes: 3 additions & 0 deletions
3
...lwc/template-compiler/src/__tests__/fixtures/attributes/attribute-uppercase/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"warnings": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
export function toPropertyName(attr: string) { | ||
let prop = ''; | ||
let shouldUpperCaseNext = false; | ||
|
||
for (let i = 0; i < attr.length; i++) { | ||
const char = attr.charAt(i); | ||
|
||
if (char === '-') { | ||
shouldUpperCaseNext = true; | ||
} else { | ||
prop += shouldUpperCaseNext ? char.toUpperCase() : char; | ||
shouldUpperCaseNext = false; | ||
} | ||
} | ||
|
||
return prop; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/integration-karma/test/template/properties/attrs/uppercaseChild/uppercaseChild.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
{Upper} | ||
</template> |
5 changes: 5 additions & 0 deletions
5
packages/integration-karma/test/template/properties/attrs/uppercaseChild/uppercaseChild.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class UppercaseCharacterPublicPropChild extends LightningElement { | ||
@api Upper = 'default value'; | ||
} |
3 changes: 3 additions & 0 deletions
3
...ges/integration-karma/test/template/properties/attrs/uppercaseParent/uppercaseParent.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<attrs-uppercase-child -upper="uppercase value from parent component"></attrs-uppercase-child> | ||
</template> |
3 changes: 3 additions & 0 deletions
3
packages/integration-karma/test/template/properties/attrs/uppercaseParent/uppercaseParent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class UppercaseCharacterPublicPropParent extends LightningElement {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters