Skip to content

Commit

Permalink
Check legacy, quote all reserved names
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmischka committed Sep 8, 2017
1 parent b367cda commit 91e04da
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/generators/dom/visitors/Element/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DomGenerator } from '../../index';
import Block from '../../Block';
import { Node } from '../../../../interfaces';
import { State } from '../../interfaces';
import reservedNames from '../../../../utils/reservedNames';

const meta = {
':Window': visitWindow,
Expand Down Expand Up @@ -246,7 +247,7 @@ function getClaimStatement(
) {
const attributes = node.attributes
.filter((attr: Node) => attr.type === 'Attribute')
.map((attr: Node) => `${quoteProp(attr.name)}: true`)
.map((attr: Node) => `${quoteProp(attr.name, generator.legacy)}: true`)
.join(', ');

const name = namespace ? node.name : node.name.toUpperCase();
Expand All @@ -256,7 +257,9 @@ function getClaimStatement(
: `{}`}, ${namespace === namespaces.svg ? true : false})`;
}

function quoteProp(name: string) {
if (/[^a-zA-Z_$0-9]/.test(name) || name === 'class') return `"${name}"`;
function quoteProp(name: string, legacy: boolean) {
const isLegacyPropName = legacy && reservedNames.has(name);

if (/[^a-zA-Z_$0-9]/.test(name) || isLegacyPropName) return `"${name}"`;
return name;
}

0 comments on commit 91e04da

Please sign in to comment.