Skip to content

Commit

Permalink
Use existing property quoting function
Browse files Browse the repository at this point in the history
  • Loading branch information
jacwright committed Aug 28, 2018
1 parent 22f4b3d commit fb734a3
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});`;
Expand All @@ -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(
Expand Down Expand Up @@ -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(', ');

Expand Down Expand Up @@ -1168,7 +1168,3 @@ const events = [
name === 'volume'
}
];

function propertize(prop) {
return /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(prop) ? `.${prop}` : `["${prop}"]`;
}

0 comments on commit fb734a3

Please sign in to comment.