Skip to content

Commit

Permalink
Merge branch 'tidy-up' into gh-637
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 30, 2017
2 parents a197c18 + 587d1f8 commit 60ff6d8
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 35 deletions.
7 changes: 5 additions & 2 deletions src/css/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function applySelector(blocks: Block[], node: Node, stack: Node[], toEncapsulate
}

else if (selector.type === 'AttributeSelector') {
if (!attributeMatches(node, selector.name.name, selector.value && unquote(selector.value.value), selector.operator, selector.flags)) return false;
if (!attributeMatches(node, selector.name.name, selector.value && unquote(selector.value), selector.operator, selector.flags)) return false;
}

else if (selector.type === 'TypeSelector') {
Expand Down Expand Up @@ -245,10 +245,13 @@ function isDynamic(value: Node) {
return value.length > 1 || value[0].type !== 'Text';
}

function unquote(str: string) {
function unquote(value: Node) {
if (value.type === 'Identifier') return value.name;
const str = value.value;
if (str[0] === str[str.length - 1] && str[0] === "'" || str[0] === '"') {
return str.slice(1, str.length - 1);
}
return str;
}

class Block {
Expand Down
10 changes: 2 additions & 8 deletions src/generators/dom/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ const preprocessors = {

node._state = getChildState(state, {
name,
parentNode: `${name}._slotted.default`,
isYield: true
parentNode: `${name}._slotted.default`
});
} else {
const slot = getStaticAttributeValue(node, 'slot');
Expand Down Expand Up @@ -373,12 +372,7 @@ const preprocessors = {

if (node.children.length) {
if (isComponent) {
const name = block.getUniqueName(
(node.name === ':Self' ? generator.name : node.name).toLowerCase()
);

if (node.children) node._slots = new Set(['default']); // TODO only include default if there are unslotted children

if (node.children) node._slots = new Set(['default']);
preprocessChildren(generator, block, node._state, node, inEachBlock, elementStack, componentStack.concat(node), stripWhitespace, nextSibling);
} else {
if (node.name === 'pre' || node.name === 'textarea') stripWhitespace = false;
Expand Down
11 changes: 0 additions & 11 deletions src/generators/dom/visitors/Element/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ export default function visitElement(
}

if (node.initialUpdate) {
// special case — if we're in a yield block, then we may call mount
// long after the fragment is created. We may therefore need to get
// the latest `state` object
// TODO what about contexts in yield blocks? do we need to do
// `var ${contextName} = [something complicated]`?
const needsStateObject = node.initialUpdateNeedsStateObject && state.isYield;

if ( needsStateObject ) {
block.builders.mount.addLine(`var state = #component.get()`);
}

block.builders.mount.addBlock(node.initialUpdate);
}

Expand Down
2 changes: 0 additions & 2 deletions src/generators/server-side-rendering/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { stringify } from '../../utils/stringify';
export class SsrGenerator extends Generator {
bindings: string[];
renderCode: string;
elementDepth: number; // TODO is this necessary? appears to be unused
appendTargets: Record<string, string> | null;
appendTarget: string | null;

Expand All @@ -25,7 +24,6 @@ export class SsrGenerator extends Generator {
super(parsed, source, name, stylesheet, options);
this.bindings = [];
this.renderCode = '';
this.elementDepth = 0;
this.appendTargets = null;

// in an SSR context, we don't need to include events, methods, oncreate or ondestroy
Expand Down
4 changes: 0 additions & 4 deletions src/generators/server-side-rendering/visitors/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,10 @@ export default function visitComponent(
generator.appendTargets = {};
generator.setAppendTarget('default');

generator.elementDepth += 1;

node.children.forEach((child: Node) => {
visit(generator, block, child);
});

generator.elementDepth -= 1;

const slotted = Object.keys(generator.appendTargets)
.map(name => `${name}: () => \`${generator.appendTargets[name]}\``)
.join(', ');
Expand Down
4 changes: 0 additions & 4 deletions src/generators/server-side-rendering/visitors/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ export default function visitElement(
if (node.name === 'textarea' && textareaContents !== undefined) {
generator.append(textareaContents);
} else {
generator.elementDepth += 1;

node.children.forEach((child: Node) => {
visit(generator, block, child);
});

generator.elementDepth -= 1;
}

if (!isVoidElementName(node.name)) {
Expand Down
4 changes: 0 additions & 4 deletions src/generators/server-side-rendering/visitors/Slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ export default function visitSlot(

generator.append(`\${options && options.slotted && options.slotted.${slotName} ? options.slotted.${slotName}() : \``);

generator.elementDepth += 1;

node.children.forEach((child: Node) => {
visit(generator, block, child);
});

generator.elementDepth -= 1;

generator.append(`\`}`);
}
3 changes: 3 additions & 0 deletions test/css/samples/attribute-selector-unquoted/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
cascade: false
};
1 change: 1 addition & 0 deletions test/css/samples/attribute-selector-unquoted/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[foo=bar][svelte-xyz]{color:red}
7 changes: 7 additions & 0 deletions test/css/samples/attribute-selector-unquoted/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div foo='bar'></div>

<style>
[foo=bar] {
color: red;
}
</style>

0 comments on commit 60ff6d8

Please sign in to comment.