0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Use existing property quoting function

This commit is contained in:
Jacob Wright 2018-08-28 09:47:17 -06:00
parent 22f4b3d4cb
commit fb734a349e

View File

@ -895,7 +895,7 @@ export default class Element extends Node {
snippet = expression.snippet;
dependencies = expression.dependencies;
} else {
snippet = `ctx${propertize(name)}`;
snippet = `ctx${quotePropIfNecessary(name)}`;
dependencies = [name];
}
const updater = `@toggleClass(${this.var}, "${name}", ${snippet});`;
@ -904,7 +904,7 @@ export default class Element extends Node {
if ((dependencies && dependencies.size > 0) || this.classDependencies.length) {
const allDeps = this.classDependencies.concat(...dependencies);
const deps = allDeps.map(dependency => `changed${propertize(dependency)}`).join(' || ');
const deps = allDeps.map(dependency => `changed${quotePropIfNecessary(dependency)}`).join(' || ');
const condition = allDeps.length > 1 ? `(${deps})` : deps;
block.builders.update.addConditional(
@ -987,7 +987,7 @@ export default class Element extends Node {
const classExpr = this.classes.map((classDir: Class) => {
const { expression, name } = classDir;
const snippet = expression ? expression.snippet : `ctx${propertize(name)}`;
const snippet = expression ? expression.snippet : `ctx${quotePropIfNecessary(name)}`;
return `${snippet} ? "${name}" : ""`;
}).join(', ');
@ -1168,7 +1168,3 @@ const events = [
name === 'volume'
}
];
function propertize(prop) {
return /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(prop) ? `.${prop}` : `["${prop}"]`;
}