8000 fix(core): imported element transform to class by idoros · Pull Request #2603 · wix/stylable · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(core): imported element transform to class #2603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/features/css-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export const hooks = createFeature<{
// native node does not resolve e.g. div
if (resolved && resolved.length > 1) {
const { symbol, meta } = getOriginDefinition(resolved);
CSSClass.namespaceClass(meta, symbol, node, selectorContext.originMeta);
if (symbol._kind === 'class') {
CSSClass.namespaceClass(meta, symbol, node, selectorContext.originMeta);
} else {
node.value = symbol.name;
}
}
},
});
Expand Down
39 changes: 39 additions & 0 deletions packages/core/test/features/css-type.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,45 @@ describe(`features/css-type`, () => {
root: `entry__root`,
});
});
it(`should resolve imported element type (no class)`, () => {
// element type is not namespaced and should be avoided
const { sheets } = testStylableCore({
'/before.st.css': `Part {}`,
'/after.st.css': `Part {}`,
'/entry.st.css': `
/* @check .entry__root Part */
.root BeforePart {}

@st-import [Part as BeforePart] from './before.st.css';
@st-import [Part as AfterPart] from './after.st.css';

/* @check .entry__root Part */
.root AfterPart {}
`,
});

const { meta, exports } = sheets['/entry.st.css'];

shouldReportNoDiagnostics(meta);

// symbols
const importBeforeDef = meta.getImportStatements()[0];
const importAfterDef = meta.getImportStatements()[1];
expect(CSSType.get(meta, `BeforePart`), `before type symbol`).to.eql({
_kind: `element`,
name: 'BeforePart',
alias: STImport.createImportSymbol(importBeforeDef, `named`, `BeforePart`, `/`),
});
expect(CSSType.get(meta, `AfterPart`), `after type symbol`).to.eql({
_kind: `element`,
name: 'AfterPart',
alias: STImport.createImportSymbol(importAfterDef, `named`, `AfterPart`, `/`),
});
// JS exports
expect(exports.classes, `not add as classes exports`).to.eql({
root: `entry__root`,
});
});
it(`should resolve deep imported element type`, () => {
testStylableCore({
'/base.st.css': ``,
Expand Down
0