From 66caecd57368c4e5ec8c331419fb8bc987adad36 Mon Sep 17 00:00:00 2001 From: Christian Kaisermann Date: Wed, 17 Feb 2021 17:33:09 -0300 Subject: [PATCH] Refactor to cssHash --- src/compiler/compile/Component.ts | 2 +- src/compiler/compile/css/Stylesheet.ts | 10 +++++----- src/compiler/compile/index.ts | 2 +- src/compiler/interfaces.ts | 4 ++-- .../{custom-scope-class => custom-css-hash}/_config.js | 2 +- .../expected.css | 0 .../input.svelte | 0 7 files changed, 10 insertions(+), 10 deletions(-) rename test/css/samples/{custom-scope-class => custom-css-hash}/_config.js (85%) rename test/css/samples/{custom-scope-class => custom-css-hash}/expected.css (100%) rename test/css/samples/{custom-scope-class => custom-css-hash}/input.svelte (100%) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index dc51b0fefd..bf22e0e6b0 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -139,7 +139,7 @@ export default class Component { filename: compile_options.filename, component_name: name, dev: compile_options.dev, - scope_class_getter: compile_options.scopeClass + get_css_hash: compile_options.cssHash }); this.stylesheet.validate(this); diff --git a/src/compiler/compile/css/Stylesheet.ts b/src/compiler/compile/css/Stylesheet.ts index d1917420b4..1b19e6cca9 100644 --- a/src/compiler/compile/css/Stylesheet.ts +++ b/src/compiler/compile/css/Stylesheet.ts @@ -2,7 +2,7 @@ import MagicString from 'magic-string'; import { walk } from 'estree-walker'; import Selector from './Selector'; import Element from '../nodes/Element'; -import { Ast, CssScopeClassGetter } from '../../interfaces'; +import { Ast, CssHashGetter } from '../../interfaces'; import Component from '../Component'; import { CssNode } from './interfaces'; import hash from '../utils/hash'; @@ -275,7 +275,7 @@ class Atrule { } } -const getDefaultScopeClass: CssScopeClassGetter = ({ hash }) => { +const get_default_css_hash: CssHashGetter = ({ hash }) => { return `svelte-${hash}`; }; @@ -299,14 +299,14 @@ export default class Stylesheet { component_name, filename, dev, - scope_class_getter = getDefaultScopeClass, + get_css_hash = get_default_css_hash, }: { source: string; ast: Ast; filename: string | undefined; component_name: string | undefined; dev: boolean; - scope_class_getter: CssScopeClassGetter; + get_css_hash: CssHashGetter; }) { this.source = source; this.ast = ast; @@ -314,7 +314,7 @@ export default class Stylesheet { this.dev = dev; if (ast.css && ast.css.children.length) { - this.id = scope_class_getter({ + this.id = get_css_hash({ filename, name: component_name, hash: hash(ast.css.content.styles), diff --git a/src/compiler/compile/index.ts b/src/compiler/compile/index.ts index 17266cafc5..d4d4e544cb 100644 --- a/src/compiler/compile/index.ts +++ b/src/compiler/compile/index.ts @@ -29,7 +29,7 @@ const valid_options = [ 'loopGuardTimeout', 'preserveComments', 'preserveWhitespace', - 'scopeClass', + 'cssHash', ]; function validate_options(options: CompileOptions, warnings: Warning[]) { diff --git a/src/compiler/interfaces.ts b/src/compiler/interfaces.ts index 3913059231..c86aed0e06 100644 --- a/src/compiler/interfaces.ts +++ b/src/compiler/interfaces.ts @@ -104,7 +104,7 @@ export interface Warning { export type ModuleFormat = 'esm' | 'cjs'; -export type CssScopeClassGetter = (args: { +export type CssHashGetter = (args: { name: string; filename: string | undefined; hash: string; @@ -131,7 +131,7 @@ export interface CompileOptions { css?: boolean; loopGuardTimeout?: number; namespace?: string; - scopeClass?: CssScopeClassGetter; + cssHash?: CssHashGetter; preserveComments?: boolean; preserveWhitespace?: boolean; diff --git a/test/css/samples/custom-scope-class/_config.js b/test/css/samples/custom-css-hash/_config.js similarity index 85% rename from test/css/samples/custom-scope-class/_config.js rename to test/css/samples/custom-css-hash/_config.js index 404e22f561..f862cb21a7 100644 --- a/test/css/samples/custom-scope-class/_config.js +++ b/test/css/samples/custom-css-hash/_config.js @@ -1,7 +1,7 @@ export default { compileOptions: { filename: 'src/components/FooSwitcher.svelte', - scopeClass({ hash, name, filename }) { + cssHash({ hash, name, filename }) { const minFilename = filename .split('/') .map(i => i.charAt(0).toLowerCase()) diff --git a/test/css/samples/custom-scope-class/expected.css b/test/css/samples/custom-css-hash/expected.css similarity index 100% rename from test/css/samples/custom-scope-class/expected.css rename to test/css/samples/custom-css-hash/expected.css diff --git a/test/css/samples/custom-scope-class/input.svelte b/test/css/samples/custom-css-hash/input.svelte similarity index 100% rename from test/css/samples/custom-scope-class/input.svelte rename to test/css/samples/custom-css-hash/input.svelte