@@ -18678,120 +18678,133 @@ async function doParse(iter, options = {}) {
1867818678 node.nam = mapping[node.nam];
1867918679 }
1868018680 if ('composes' == node.nam.toLowerCase()) {
18681- const token = node.val.find(t => t.typ == exports.EnumToken.ComposesSelectorNodeType);
18682- if (token == null) {
18683- continue;
18681+ const tokens = [];
18682+ let isValid = true;
18683+ for (const token of node.val) {
18684+ if (token.typ == exports.EnumToken.ComposesSelectorNodeType) {
18685+ if (!(token.r == null || token.r.typ == exports.EnumToken.StringTokenType || token.r.typ == exports.EnumToken.IdenTokenType)) {
18686+ errors.push({
18687+ action: 'drop',
18688+ message: `composes '${exports.EnumToken[token.r.typ]}' is not supported`,
18689+ node
18690+ });
18691+ isValid = false;
18692+ break;
18693+ }
18694+ tokens.push(token);
18695+ }
1868418696 }
1868518697 // find parent rule
1868618698 let parentRule = node.parent;
1868718699 while (parentRule != null && parentRule.typ != exports.EnumToken.RuleNodeType) {
1868818700 parentRule = parentRule.parent;
1868918701 }
18690- // composes: a b c;
18691- if (token.r == null) {
18692- for (const rule of token.l) {
18693- if (rule.typ == exports.EnumToken.WhitespaceTokenType || rule.typ == exports.EnumToken.CommentTokenType) {
18694- continue;
18702+ if (!isValid) {
18703+ parentRule.chi.splice(parentRule.chi.indexOf(node), 1);
18704+ continue;
18705+ }
18706+ for (const token of tokens) {
18707+ // composes: a b c;
18708+ if (token.r == null) {
18709+ for (const rule of token.l) {
18710+ if (rule.typ == exports.EnumToken.WhitespaceTokenType || rule.typ == exports.EnumToken.CommentTokenType) {
18711+ continue;
18712+ }
18713+ if (!(rule.val in mapping)) {
18714+ let result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? rule.val : moduleSettings.generateScopedName(rule.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
18715+ let value = result instanceof Promise ? await result : result;
18716+ mapping[rule.val] = (rule.typ == exports.EnumToken.DashedIdenTokenType ? '--' : '') + (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
18717+ revMapping[mapping[rule.val]] = rule.val;
18718+ }
18719+ if (parentRule != null) {
18720+ for (const tk of parentRule.tokens) {
18721+ if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
18722+ const val = tk.val.slice(1);
18723+ if (val in revMapping) {
18724+ const key = revMapping[val];
18725+ mapping[key] = [...new Set([...mapping[key].split(' '), mapping[rule.val]])].join(' ');
18726+ }
18727+ }
18728+ }
18729+ }
1869518730 }
18696- if (!(rule.val in mapping)) {
18697- let result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? rule.val : moduleSettings.generateScopedName(rule.val, moduleSettings.filePath, moduleSettings.pattern, moduleSettings.hashLength);
18698- let value = result instanceof Promise ? await result : result;
18699- mapping[rule.val] = (rule.typ == exports.EnumToken.DashedIdenTokenType ? '--' : '') + (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
18700- revMapping[mapping[rule.val]] = rule.val;
18731+ }
18732+ // composes: a b c from 'file.css';
18733+ else if (token.r.typ == exports.EnumToken.String) {
18734+ const url = token.r.val.slice(1, -1);
18735+ const src = options.resolve(url, options.dirname(options.src), options.cwd);
18736+ const result = options.load(url, options.src);
18737+ const stream = result instanceof Promise || Object.getPrototypeOf(result).constructor.name == 'AsyncFunction' ? await result : result;
18738+ const root = await doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize$1({
18739+ stream,
18740+ buffer: '',
18741+ position: { ind: 0, lin: 1, col: 1 },
18742+ currentPosition: { ind: -1, lin: 1, col: 0 }
18743+ }), Object.assign({}, options, {
18744+ minify: false,
18745+ setParent: false,
18746+ src: src.absolute
18747+ }));
18748+ const srcIndex = (src.relative.startsWith('/') ? '' : './') + src.relative;
18749+ if (Object.keys(root.mapping).length > 0) {
18750+ importMapping[srcIndex] = {};
1870118751 }
1870218752 if (parentRule != null) {
1870318753 for (const tk of parentRule.tokens) {
1870418754 if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
1870518755 const val = tk.val.slice(1);
1870618756 if (val in revMapping) {
1870718757 const key = revMapping[val];
18708- mapping[key] = [...new Set([...mapping[key].split(' '), mapping[rule.val]])].join(' ');
18758+ const values = [];
18759+ for (const iden of token.l) {
18760+ if (iden.typ != exports.EnumToken.IdenTokenType && iden.typ != exports.EnumToken.DashedIdenTokenType) {
18761+ continue;
18762+ }
18763+ if (!(iden.val in root.mapping)) {
18764+ const result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? iden.val : moduleSettings.generateScopedName(iden.val, url, moduleSettings.pattern, moduleSettings.hashLength);
18765+ let value = result instanceof Promise ? await result : result;
18766+ root.mapping[iden.val] = (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
18767+ root.revMapping[root.mapping[iden.val]] = iden.val;
18768+ }
18769+ importMapping[srcIndex][iden.val] = root.mapping[iden.val];
18770+ values.push(root.mapping[iden.val]);
18771+ }
18772+ mapping[key] = [...new Set([...mapping[key].split(' '), ...values])].join(' ');
1870918773 }
1871018774 }
1871118775 }
1871218776 }
1871318777 }
18714- }
18715- // composes: a b c from 'file.css';
18716- else if (token.r.typ == exports.EnumToken.String) {
18717- const url = token.r.val.slice(1, -1);
18718- const src = options.resolve(url, options.dirname(options.src), options.cwd);
18719- const result = options.load(url, options.src);
18720- const stream = result instanceof Promise || Object.getPrototypeOf(result).constructor.name == 'AsyncFunction' ? await result : result;
18721- const root = await doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize$1({
18722- stream,
18723- buffer: '',
18724- position: { ind: 0, lin: 1, col: 1 },
18725- currentPosition: { ind: -1, lin: 1, col: 0 }
18726- }), Object.assign({}, options, {
18727- minify: false,
18728- setParent: false,
18729- src: src.absolute
18730- }));
18731- if (Object.keys(root.mapping).length > 0) {
18732- importMapping[(src.relative.startsWith('/') ? '' : './') + src.relative] = root.mapping;
18733- }
18734- if (parentRule != null) {
18735- for (const tk of parentRule.tokens) {
18736- if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
18737- const val = tk.val.slice(1);
18738- if (val in revMapping) {
18739- const key = revMapping[val];
18740- const values = [];
18741- for (const iden of token.l) {
18742- if (iden.typ != exports.EnumToken.IdenTokenType && iden.typ != exports.EnumToken.DashedIdenTokenType) {
18743- continue;
18744- }
18745- if (!(iden.val in root.mapping)) {
18746- const result = (moduleSettings.scoped & exports.ModuleScopeEnumOptions.Global) ? iden.val : moduleSettings.generateScopedName(iden.val, url, moduleSettings.pattern, moduleSettings.hashLength);
18747- let value = result instanceof Promise ? await result : result;
18748- root.mapping[iden.val] = (moduleSettings.naming & exports.ModuleCaseTransformEnum.DashCaseOnly || moduleSettings.naming & exports.ModuleCaseTransformEnum.CamelCaseOnly ? getKeyName(value, moduleSettings.naming) : value);
18749- root.revMapping[root.mapping[iden.val]] = iden.val;
18778+ // composes: a b c from global;
18779+ else if (token.r.typ == exports.EnumToken.IdenTokenType) {
18780+ // global
18781+ if (parentRule != null) {
18782+ if ('global' == token.r.val.toLowerCase()) {
18783+ for (const tk of parentRule.tokens) {
18784+ if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
18785+ const val = tk.val.slice(1);
18786+ if (val in revMapping) {
18787+ const key = revMapping[val];
18788+ mapping[key] = [...new Set([...mapping[key].split(' '), ...(token.l.reduce((acc, curr) => {
18789+ if (curr.typ == exports.EnumToken.IdenTokenType) {
18790+ acc.push(curr.val);
18791+ }
18792+ return acc;
18793+ }, []))])].join(' ');
1875018794 }
18751- values.push(root.mapping[iden.val]);
1875218795 }
18753- mapping[key] = [...new Set([...mapping[key].split(' '), ...values])].join(' ');
1875418796 }
1875518797 }
18756- }
18757- }
18758- }
18759- // composes: a b c from global;
18760- else if (token.r.typ == exports.EnumToken.IdenTokenType) {
18761- // global
18762- if (parentRule != null) {
18763- if ('global' == token.r.val.toLowerCase()) {
18764- for (const tk of parentRule.tokens) {
18765- if (tk.typ == exports.EnumToken.ClassSelectorTokenType) {
18766- const val = tk.val.slice(1);
18767- if (val in revMapping) {
18768- const key = revMapping[val];
18769- mapping[key] = [...new Set([...mapping[key].split(' '), ...(token.l.reduce((acc, curr) => {
18770- if (curr.typ == exports.EnumToken.IdenTokenType) {
18771- acc.push(curr.val);
18772- }
18773- return acc;
18774- }, []))])].join(' ');
18775- }
18776- }
18798+ else {
18799+ errors.push({
18800+ action: 'drop',
18801+ message: `composes '${token.r.val}' is not supported`,
18802+ node
18803+ });
1877718804 }
1877818805 }
18779- else {
18780- errors.push({
18781- action: 'drop',
18782- message: `composes '${token.r.val}' is not supported`,
18783- node
18784- });
18785- }
1878618806 }
1878718807 }
18788- else {
18789- errors.push({
18790- action: 'drop',
18791- message: `composes '${exports.EnumToken[token.r.typ]}' is not supported`,
18792- node
18793- });
18794- }
1879518808 parentRule.chi.splice(parentRule.chi.indexOf(node), 1);
1879618809 }
1879718810 if (node.nam == 'grid-template-areas') {
0 commit comments