Skip to content

Commit

Permalink
fix: imported element transform to class
Browse files Browse the repository at this point in the history
- taken from fix of v5
  • Loading branch information
idoros committed Jul 11, 2022
1 parent ffb1506 commit e4d0a25
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
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 @@ -67,7 +67,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 @@ -156,6 +156,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 comments on commit e4d0a25

Please sign in to comment.