svelte-preprocess-cssmodules
Advanced tools
Comparing version 2.0.0 to 2.0.1
# Svelte preprocess CSS Modules, changelog | ||
## 2.0.1 (May 6, 2021) | ||
- Fix shorthand directive breaking regular directive | ||
## 2.0.0 (May 1, 2021) | ||
@@ -4,0 +7,0 @@ New public release |
@@ -32,3 +32,2 @@ "use strict"; | ||
} | ||
// eslint-disable-next-line prefer-const | ||
let { mode, hashSeeder } = pluginOptions; | ||
@@ -66,3 +65,2 @@ if (lib_1.hasModuleAttribute(ast)) { | ||
}); | ||
// eslint-disable-next-line no-multi-assign | ||
exports.default = exports = module.exports = (options) => { | ||
@@ -69,0 +67,0 @@ pluginOptions = Object.assign(Object.assign({}, pluginOptions), options); |
import { PluginOptions } from '../types'; | ||
/** | ||
* Create the interpolated name | ||
* @param filename tthe resource filename | ||
* @param markup Markup content | ||
* @param style Stylesheet content | ||
* @param className the className | ||
* @param pluginOptions preprocess-cssmodules options | ||
* @return the interpolated name | ||
*/ | ||
declare function createCssModulesClassName(filename: string, markup: string, style: string, className: string, pluginOptions: PluginOptions): string; | ||
export default createCssModulesClassName; |
@@ -9,9 +9,2 @@ "use strict"; | ||
const PATTERN_PATH_UNALLOWED = /[<>:"/\\|?*]/g; | ||
/** | ||
* interpolateName, adjusted version of loader-utils/interpolateName | ||
* @param resourcePath The file resourcePath | ||
* @param localName The local name/rules to replace | ||
* @param content The content to base the hash on | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function interpolateName(resourcePath, localName, content) { | ||
@@ -49,9 +42,2 @@ const filename = localName || '[hash].[ext]'; | ||
} | ||
/** | ||
* generateName | ||
* @param resourcePath The file resourcePath | ||
* @param style The style content | ||
* @param className The cssModules className | ||
* @param localIdentName The localIdentName rule | ||
*/ | ||
function generateName(resourcePath, style, className, pluginOptions) { | ||
@@ -68,11 +54,8 @@ const filePath = resourcePath; | ||
let interpolatedName = interpolateName(resourcePath, localName, hashSeeder).replace(/\./g, '-'); | ||
// replace unwanted characters from [path] | ||
if (PATTERN_PATH_UNALLOWED.test(interpolatedName)) { | ||
interpolatedName = interpolatedName.replace(PATTERN_PATH_UNALLOWED, '_'); | ||
} | ||
// prevent class error when the generated classname starts from a non word charater | ||
if (/^(?![a-zA-Z_])/.test(interpolatedName)) { | ||
interpolatedName = `_${interpolatedName}`; | ||
} | ||
// prevent svelte "Unused CSS selector" warning when the generated classname ends by `-` | ||
if (interpolatedName.slice(-1) === '-') { | ||
@@ -83,11 +66,2 @@ interpolatedName = interpolatedName.slice(0, -1); | ||
} | ||
/** | ||
* Create the interpolated name | ||
* @param filename tthe resource filename | ||
* @param markup Markup content | ||
* @param style Stylesheet content | ||
* @param className the className | ||
* @param pluginOptions preprocess-cssmodules options | ||
* @return the interpolated name | ||
*/ | ||
function createCssModulesClassName(filename, markup, style, className, pluginOptions) { | ||
@@ -94,0 +68,0 @@ const interpolatedName = generateName(filename, style, className, pluginOptions); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLocalIdent = void 0; | ||
// eslint-disable-next-line max-len | ||
exports.getLocalIdent = (_context, localIdentName) => localIdentName.interpolatedName; |
import type { Ast } from 'svelte/types/compiler/interfaces.d'; | ||
/** | ||
* Check if a file requires processing | ||
* @param includePaths List of allowd paths | ||
* @param filename the current filename to compare with the paths | ||
* @returns The permission status | ||
*/ | ||
export declare const isFileIncluded: (includePaths: string[], filename: string) => Promise<boolean>; | ||
/** | ||
* Check if a component is importing external module stylesheets | ||
* @param content The component content | ||
* @returns The status | ||
*/ | ||
export declare const hasModuleImports: (content: string) => boolean; | ||
/** | ||
* Check if a component style demands CSS Modules | ||
* @param ast the component content tree | ||
* @returns The status | ||
*/ | ||
export declare const hasModuleAttribute: (ast: Ast) => boolean; |
@@ -17,8 +17,2 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
/** | ||
* Check if a file requires processing | ||
* @param includePaths List of allowd paths | ||
* @param filename the current filename to compare with the paths | ||
* @returns The permission status | ||
*/ | ||
exports.isFileIncluded = (includePaths, filename) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -40,7 +34,2 @@ if (includePaths.length < 1) { | ||
}); | ||
/** | ||
* Check if a component is importing external module stylesheets | ||
* @param content The component content | ||
* @returns The status | ||
*/ | ||
exports.hasModuleImports = (content) => { | ||
@@ -50,7 +39,2 @@ const pattern = /(?<!\/\/\s*)import\s*(?:(.+)\s+from\s+)?['|"](.+?(module\.s?css))['|"];?/gm; | ||
}; | ||
/** | ||
* Check if a component style demands CSS Modules | ||
* @param ast the component content tree | ||
* @returns The status | ||
*/ | ||
exports.hasModuleAttribute = (ast) => { | ||
@@ -57,0 +41,0 @@ var _a; |
import Processor from '../processors/processor'; | ||
declare const _default: (processor: Processor) => void; | ||
/** | ||
* Parse CssModules Imports | ||
*/ | ||
export default _default; |
@@ -25,4 +25,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable no-param-reassign */ | ||
// @ts-expect-error walk is not in d.ts | ||
const compiler_1 = require("svelte/compiler"); | ||
@@ -32,5 +30,2 @@ const path_1 = __importDefault(require("path")); | ||
const magic_string_1 = __importDefault(require("magic-string")); | ||
/** | ||
* Parse CssModules Imports | ||
*/ | ||
exports.default = (processor) => { | ||
@@ -90,3 +85,3 @@ const backup = { | ||
if (error) { | ||
throw new Error(err); // not found in node_modules packages either, throw orignal error | ||
throw new Error(err); | ||
} | ||
@@ -93,0 +88,0 @@ }); |
import Processor from '../processors/processor'; | ||
declare const _default: (processor: Processor) => void; | ||
/** | ||
* Parse the template markup to update the class attributes with CSS modules | ||
* @param processor The CSS Module Processor | ||
*/ | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// @ts-expect-error walk is not in d.ts | ||
const compiler_1 = require("svelte/compiler"); | ||
/** | ||
* Update a string of multiple Classes | ||
* @param processor The CSS Module Processor | ||
* @param classNames The attribute value containing one or multiple classes | ||
* @returns the CSS Modules classnames | ||
*/ | ||
const updateMultipleClasses = (processor, classNames) => { | ||
@@ -25,7 +18,2 @@ const classes = classNames.split(' '); | ||
}; | ||
/** | ||
* Parse and update classes of a js expression element | ||
* @param processor: The CSS Module Processor | ||
* @param expression The expression node (consequent, alternate) | ||
*/ | ||
const parseExpression = (processor, expression) => { | ||
@@ -37,6 +25,2 @@ if (expression.type === 'Literal') { | ||
}; | ||
/** | ||
* Parse the template markup to update the class attributes with CSS modules | ||
* @param processor The CSS Module Processor | ||
*/ | ||
exports.default = (processor) => { | ||
@@ -73,3 +57,3 @@ const directiveLength = 'class:'.length; | ||
const end = start + item.name.length; | ||
if (item.expression.type === 'Identifier') { | ||
if (item.expression.type === 'Identifier' && item.name === item.expression.name) { | ||
processor.magicContent.overwrite(start, end, `${processor.cssModuleList[name]}={${item.name}}`); | ||
@@ -76,0 +60,0 @@ } |
@@ -15,12 +15,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// @ts-expect-error walk is not in d.ts | ||
const compiler_1 = require("svelte/compiler"); | ||
const processor_1 = __importDefault(require("./processor")); | ||
/** | ||
* Update the selector boundaries | ||
* @param boundaries The current boundaries | ||
* @param start the new boundary start value | ||
* @param end the new boundary end value | ||
* @returns the updated boundaries | ||
*/ | ||
const updateSelectorBoundaries = (boundaries, start, end) => { | ||
@@ -37,6 +29,2 @@ var _a; | ||
}; | ||
/** | ||
* The mixed style parser | ||
* @param processor The CSS Module Processor | ||
*/ | ||
const parser = (processor) => { | ||
@@ -43,0 +31,0 @@ compiler_1.walk(processor.ast, { |
@@ -15,12 +15,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// @ts-expect-error walk is not in d.ts | ||
const compiler_1 = require("svelte/compiler"); | ||
const processor_1 = __importDefault(require("./processor")); | ||
/** | ||
* Update the selector boundaries | ||
* @param boundaries The current boundaries | ||
* @param start the new boundary start value | ||
* @param end the new boundary end value | ||
* @returns the updated boundaries | ||
*/ | ||
const updateSelectorBoundaries = (boundaries, start, end) => { | ||
@@ -38,6 +30,2 @@ var _a; | ||
}; | ||
/** | ||
* The native style parser | ||
* @param processor The CSS Module Processor | ||
*/ | ||
const parser = (processor) => { | ||
@@ -44,0 +32,0 @@ let selectorBoundaries = []; |
@@ -20,24 +20,6 @@ import MagicString from 'magic-string'; | ||
constructor(ast: Ast, content: string, filename: string, options: PluginOptions, parser: (param: Processor) => void); | ||
/** | ||
* Create CssModule classname | ||
* @param name The raw classname | ||
* @returns The generated module classname | ||
*/ | ||
createModuleClassname: (name: string) => string; | ||
/** | ||
* Add CssModule data to list | ||
* @param name The raw classname | ||
* @param value The generated module classname | ||
*/ | ||
addModule: (name: string, value: string) => void; | ||
/** | ||
* Parse pseudo selector :local() | ||
* @param node The ast "Selector" node to parse | ||
*/ | ||
parsePseudoLocalSelectors: (node: TemplateNode) => void; | ||
/** | ||
* Parse component | ||
* @returns The CssModule updated component | ||
*/ | ||
parse: () => string; | ||
} |
@@ -15,7 +15,2 @@ "use strict"; | ||
this.isParsingImports = false; | ||
/** | ||
* Create CssModule classname | ||
* @param name The raw classname | ||
* @returns The generated module classname | ||
*/ | ||
this.createModuleClassname = (name) => { | ||
@@ -25,7 +20,2 @@ const generatedClassName = lib_1.createClassName(this.filename, this.rawContent, this.ast.css.content.styles, name, this.options); | ||
}; | ||
/** | ||
* Add CssModule data to list | ||
* @param name The raw classname | ||
* @param value The generated module classname | ||
*/ | ||
this.addModule = (name, value) => { | ||
@@ -37,6 +27,2 @@ if (this.isParsingImports) { | ||
}; | ||
/** | ||
* Parse pseudo selector :local() | ||
* @param node The ast "Selector" node to parse | ||
*/ | ||
this.parsePseudoLocalSelectors = (node) => { | ||
@@ -51,6 +37,2 @@ const pseudoLocalSelectors = node.children.filter((item) => item.type === 'PseudoClassSelector' && item.name === 'local'); | ||
}; | ||
/** | ||
* Parse component | ||
* @returns The CssModule updated component | ||
*/ | ||
this.parse = () => { | ||
@@ -57,0 +39,0 @@ if (lib_1.hasModuleAttribute(this.ast)) { |
@@ -15,9 +15,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// @ts-expect-error walk is not in d.ts | ||
const compiler_1 = require("svelte/compiler"); | ||
const processor_1 = __importDefault(require("./processor")); | ||
/** | ||
* The scoped style parser | ||
* @param processor The CSS Module Processor | ||
*/ | ||
const parser = (processor) => { | ||
@@ -24,0 +19,0 @@ compiler_1.walk(processor.ast, { |
{ | ||
"name": "svelte-preprocess-cssmodules", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Svelte preprocessor to generate CSS Modules classname on Svelte components", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -11,3 +11,3 @@ # Svelte preprocess CSS Modules | ||
- [Modes](#modes) | ||
- [Work with class directive](#work-with-class-directive) | ||
- [Class directive](#class-directive) | ||
- [Local selector](#local-selector) | ||
@@ -23,3 +23,3 @@ - [Import styles from an external stylesheet](#import-styles-from-an-external-stylesheet) | ||
- [Options](#options) | ||
- [Migration from v1](#migration-from-v1) | ||
- [Migrating from v1](#migrating-from-v1) | ||
- [Code example](#code-example) | ||
@@ -104,3 +104,3 @@ - [Why CSS Modules on Svelte](#why-css-modules-on-svelte) | ||
### Work with class directive | ||
### Class directive | ||
@@ -107,0 +107,0 @@ Toggle a class on an element. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59725
766