-
Notifications
You must be signed in to change notification settings - Fork 393
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): warning for slot attribute not at the top level
- Loading branch information
Showing
8 changed files
with
267 additions
and
1 deletion.
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
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
7 changes: 7 additions & 0 deletions
7
packages/@lwc/template-compiler/src/__tests__/fixtures/slots/top-level-warning/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,7 @@ | ||
<template> | ||
<x-inner> | ||
<div> | ||
<span slot="foo">I am the foo slot</span> | ||
</div> | ||
</x-inner> | ||
</template> |
170 changes: 170 additions & 0 deletions
170
packages/@lwc/template-compiler/src/__tests__/fixtures/slots/top-level-warning/ast.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,170 @@ | ||
{ | ||
"root": { | ||
"type": "Root", | ||
"location": { | ||
"startLine": 1, | ||
"startColumn": 1, | ||
"endLine": 7, | ||
"endColumn": 12, | ||
"start": 0, | ||
"end": 134, | ||
"startTag": { | ||
"startLine": 1, | ||
"startColumn": 1, | ||
"endLine": 1, | ||
"endColumn": 11, | ||
"start": 0, | ||
"end": 10 | ||
}, | ||
"endTag": { | ||
"startLine": 7, | ||
"startColumn": 1, | ||
"endLine": 7, | ||
"endColumn": 12, | ||
"start": 123, | ||
"end": 134 | ||
} | ||
}, | ||
"directives": [], | ||
"children": [ | ||
{ | ||
"type": "Component", | ||
"name": "x-inner", | ||
"namespace": "http://www.w3.org/1999/xhtml", | ||
"location": { | ||
"startLine": 2, | ||
"startColumn": 5, | ||
"endLine": 6, | ||
"endColumn": 15, | ||
"start": 15, | ||
"end": 122, | ||
"startTag": { | ||
"startLine": 2, | ||
"startColumn": 5, | ||
"endLine": 2, | ||
"endColumn": 14, | ||
"start": 15, | ||
"end": 24 | ||
}, | ||
"endTag": { | ||
"startLine": 6, | ||
"startColumn": 5, | ||
"endLine": 6, | ||
"endColumn": 15, | ||
"start": 112, | ||
"end": 122 | ||
} | ||
}, | ||
"attributes": [], | ||
"properties": [], | ||
"directives": [], | ||
"listeners": [], | ||
"children": [ | ||
{ | ||
"type": "Element", | ||
"name": "div", | ||
"namespace": "http://www.w3.org/1999/xhtml", | ||
"location": { | ||
"startLine": 3, | ||
"startColumn": 9, | ||
"endLine": 5, | ||
"endColumn": 15, | ||
"start": 33, | ||
"end": 107, | ||
"startTag": { | ||
"startLine": 3, | ||
"startColumn": 9, | ||
"endLine": 3, | ||
"endColumn": 14, | ||
"start": 33, | ||
"end": 38 | ||
}, | ||
"endTag": { | ||
"startLine": 5, | ||
"startColumn": 9, | ||
"endLine": 5, | ||
"endColumn": 15, | ||
"start": 101, | ||
"end": 107 | ||
} | ||
}, | ||
"attributes": [], | ||
"properties": [], | ||
"directives": [], | ||
"listeners": [], | ||
"children": [ | ||
{ | ||
"type": "Element", | ||
"name": "span", | ||
"namespace": "http://www.w3.org/1999/xhtml", | ||
"location": { | ||
"startLine": 4, | ||
"startColumn": 13, | ||
"endLine": 4, | ||
"endColumn": 54, | ||
"start": 51, | ||
"end": 92, | ||
"startTag": { | ||
"startLine": 4, | ||
"startColumn": 13, | ||
"endLine": 4, | ||
"endColumn": 30, | ||
"start": 51, | ||
"end": 68 | ||
}, | ||
"endTag": { | ||
"startLine": 4, | ||
"startColumn": 47, | ||
"endLine": 4, | ||
"endColumn": 54, | ||
"start": 85, | ||
"end": 92 | ||
} | ||
}, | ||
"attributes": [ | ||
{ | ||
"type": "Attribute", | ||
"name": "slot", | ||
"value": { | ||
"type": "Literal", | ||
"value": "foo" | ||
}, | ||
"location": { | ||
"startLine": 4, | ||
"startColumn": 19, | ||
"endLine": 4, | ||
"endColumn": 29, | ||
"start": 57, | ||
"end": 67 | ||
} | ||
} | ||
], | ||
"properties": [], | ||
"directives": [], | ||
"listeners": [], | ||
"children": [ | ||
{ | ||
"type": "Text", | ||
"raw": "I am the foo slot", | ||
"value": { | ||
"type": "Literal", | ||
"value": "I am the foo slot" | ||
}, | ||
"location": { | ||
"startLine": 4, | ||
"startColumn": 30, | ||
"endLine": 4, | ||
"endColumn": 47, | ||
"start": 68, | ||
"end": 85 | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/@lwc/template-compiler/src/__tests__/fixtures/slots/top-level-warning/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,36 @@ | ||
import _implicitStylesheets from "./top-level-warning.css"; | ||
import _implicitScopedStylesheets from "./top-level-warning.scoped.css?scoped=true"; | ||
import _xInner from "x/inner"; | ||
import { freezeTemplate, registerTemplate } from "lwc"; | ||
const stc0 = { | ||
key: 0, | ||
}; | ||
const stc1 = { | ||
key: 1, | ||
}; | ||
const stc2 = { | ||
slotAssignment: "foo", | ||
key: 2, | ||
}; | ||
function tmpl($api, $cmp, $slotset, $ctx) { | ||
const { t: api_text, h: api_element, c: api_custom_element } = $api; | ||
return [ | ||
api_custom_element("x-inner", _xInner, stc0, [ | ||
api_element("div", stc1, [ | ||
api_element("span", stc2, [api_text("I am the foo slot")]), | ||
]), | ||
]), | ||
]; | ||
/*LWC compiler vX.X.X*/ | ||
} | ||
export default registerTemplate(tmpl); | ||
tmpl.stylesheets = []; | ||
tmpl.stylesheetToken = "lwc-2vrd1nfb7kv"; | ||
tmpl.legacyStylesheetToken = "x-top-level-warning_top-level-warning"; | ||
if (_implicitStylesheets) { | ||
tmpl.stylesheets.push.apply(tmpl.stylesheets, _implicitStylesheets); | ||
} | ||
if (_implicitScopedStylesheets) { | ||
tmpl.stylesheets.push.apply(tmpl.stylesheets, _implicitScopedStylesheets); | ||
} | ||
freezeTemplate(tmpl); |
15 changes: 15 additions & 0 deletions
15
packages/@lwc/template-compiler/src/__tests__/fixtures/slots/top-level-warning/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,15 @@ | ||
{ | ||
"warnings": [ | ||
{ | ||
"code": 1201, | ||
"message": "LWC1201: The slot attribute in <span> will likely be ignored by its parent <div>.", | ||
"level": 2, | ||
"location": { | ||
"line": 4, | ||
"column": 19, | ||
"start": 57, | ||
"length": 10 | ||
} | ||
} | ||
] | ||
} |
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