Skip to content

don't use dataset with svg elements #995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2e56d10
start moving logic into Node and its subclasses
Rich-Harris Dec 6, 2017
4b31992
remove unused code
Rich-Harris Dec 6, 2017
39f1af2
start implementing build() methods
Rich-Harris Dec 7, 2017
8e9e323
start moving build logic into individual nodes
Rich-Harris Dec 9, 2017
c6d49b7
move some code around
Rich-Harris Dec 9, 2017
daaad80
remove some unused code
Rich-Harris Dec 9, 2017
e8e05e7
move Slot logic
Rich-Harris Dec 9, 2017
425d019
move attribute logic
Rich-Harris Dec 9, 2017
8072f6a
move binding logic
Rich-Harris Dec 9, 2017
596c432
move shared MustacheTag/RawMustacheTag logic
Rich-Harris Dec 9, 2017
56f34c7
remove elementStack
Rich-Harris Dec 9, 2017
fd24a5c
remove componentStack
Rich-Harris Dec 9, 2017
0cf9259
remove inEachBlock
Rich-Harris Dec 9, 2017
67aca17
Merge branch 'master' into gh-979
Rich-Harris Dec 9, 2017
f4888dd
fix a few typescript issues
Rich-Harris Dec 9, 2017
7f77a10
remove confusing state object from init
Rich-Harris Dec 9, 2017
f6ac3a4
remove some unused stuff
Rich-Harris Dec 9, 2017
e30dc8e
put namespace on Element nodes
Rich-Harris Dec 9, 2017
8eacc25
tidy up
Rich-Harris Dec 9, 2017
48ed685
more tidying up
Rich-Harris Dec 9, 2017
05d63e6
simplify
Rich-Harris Dec 9, 2017
16bac3b
more simplification
Rich-Harris Dec 9, 2017
433623c
rename some stuff to be clearer
Rich-Harris Dec 9, 2017
afa996c
remove unused imports
Rich-Harris Dec 9, 2017
e9dc123
DRY out
Rich-Harris Dec 9, 2017
ea418cd
more tidying up
Rich-Harris Dec 9, 2017
3fa83e3
rename _block to block
Rich-Harris Dec 9, 2017
9b2a7e1
remove preprocess from ssr renderer
Rich-Harris Dec 9, 2017
e974fdc
more tidying up
Rich-Harris Dec 9, 2017
a72a6ca
small tweak, possibly ahead of a much larger one
Rich-Harris Dec 9, 2017
f7d4994
tidy up
Rich-Harris Dec 9, 2017
cf94217
remove unused code
Rich-Harris Dec 10, 2017
7534372
dont use dataset with svg elements - fixes #982
Rich-Harris Dec 10, 2017
c4056ab
merge master -> gh-982
Rich-Harris Dec 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove elementStack
  • Loading branch information
Rich-Harris committed Dec 9, 2017
commit 56f34c70c18f66f91124ed70495b3d7143230001
13 changes: 10 additions & 3 deletions src/css/Stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { walk } from 'estree-walker';
import { getLocator } from 'locate-character';
import Selector from './Selector';
import getCodeFrame from '../utils/getCodeFrame';
import Element from '../generators/nodes/Element';
import { Validator } from '../validate/index';
import { Node, Parsed, Warning } from '../interfaces';

Expand All @@ -19,7 +20,7 @@ class Rule {
this.declarations = node.block.children.map((node: Node) => new Declaration(node));
}

apply(node: Node, stack: Node[]) {
apply(node: Element, stack: Element[]) {
this.selectors.forEach(selector => selector.apply(node, stack)); // TODO move the logic in here?
}

Expand Down Expand Up @@ -159,7 +160,7 @@ class Atrule {
this.children = [];
}

apply(node: Node, stack: Node[]) {
apply(node: Element, stack: Element[]) {
if (this.node.name === 'media') {
this.children.forEach(child => {
child.apply(node, stack);
Expand Down Expand Up @@ -330,9 +331,15 @@ export default class Stylesheet {
}
}

apply(node: Node, stack: Node[]) {
apply(node: Element) {
if (!this.hasStyles) return;

const stack: Element[] = [];
let parent: Node = node;
while (parent = parent.parent) {
if (parent.type === 'Element') stack.unshift(<Element>parent);
}

if (this.cascade) {
if (stack.length === 0) node._needsCssAttribute = true;
return;
Expand Down
9 changes: 2 additions & 7 deletions src/generators/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,11 @@ export default function dom(
namespace,
} = generator;

parsed.html.init();
const { block, state } = parsed.html;
parsed.html.build();
const { block } = parsed.html;

generator.stylesheet.warnOnUnusedSelectors(options.onwarn);

// parsed.html.children.forEach((node: Node) => {
// visit(generator, block, state, node, [], []);
// });
parsed.html.build(block, state);

const builder = new CodeBuilder();
const computationBuilder = new CodeBuilder();
const computationDeps = new Set();
Expand Down
6 changes: 2 additions & 4 deletions src/generators/nodes/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default class AwaitBlock extends Node {
block: Block,
state: State,
inEachBlock: boolean,
elementStack: Node[],
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
Expand Down Expand Up @@ -54,7 +53,7 @@ export default class AwaitBlock extends Node {

child._state = state.child();

child.initChildren(child._block, child._state, inEachBlock, elementStack, componentStack, stripWhitespace, nextSibling);
child.initChildren(child._block, child._state, inEachBlock, componentStack, stripWhitespace, nextSibling);
this.generator.blocks.push(child._block);

if (child._block.dependencies.size > 0) {
Expand All @@ -71,7 +70,6 @@ export default class AwaitBlock extends Node {
build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const name = this.var;
Expand Down Expand Up @@ -213,7 +211,7 @@ export default class AwaitBlock extends Node {

[this.pending, this.then, this.catch].forEach(status => {
status.children.forEach(child => {
child.build(status._block, status._state, elementStack, componentStack);
child.build(status._block, status._state, componentStack);
});
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/generators/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default class Component extends Node {
block: Block,
state: State,
inEachBlock: boolean,
elementStack: Node[],
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
Expand Down Expand Up @@ -63,15 +62,14 @@ export default class Component extends Node {
this._slots = new Set(['default']);

this.children.forEach(child => {
child.init(block, state, inEachBlock, elementStack, componentStack.concat(this), stripWhitespace, nextSibling);
child.init(block, state, inEachBlock, componentStack.concat(this), stripWhitespace, nextSibling);
});
}
}

build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const { generator } = this;
Expand All @@ -86,7 +84,7 @@ export default class Component extends Node {
componentInitProperties.push(`slots: { ${slots.join(', ')} }`);

this.children.forEach((child: Node) => {
child.build(block, this._state, elementStack, componentStack.concat(this));
child.build(block, this._state, componentStack.concat(this));
});
}

Expand Down
9 changes: 3 additions & 6 deletions src/generators/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export default class EachBlock extends Node {
block: Block,
state: State,
inEachBlock: boolean,
elementStack: Node[],
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
Expand Down Expand Up @@ -90,7 +89,7 @@ export default class EachBlock extends Node {
});

this.generator.blocks.push(this._block);
this.initChildren(this._block, this._state, true, elementStack, componentStack, stripWhitespace, nextSibling);
this.initChildren(this._block, this._state, true, componentStack, stripWhitespace, nextSibling);
block.addDependencies(this._block.dependencies);
this._block.hasUpdateMethod = this._block.dependencies.size > 0;

Expand All @@ -107,7 +106,6 @@ export default class EachBlock extends Node {
this.else._block,
this.else._state,
inEachBlock,
elementStack,
componentStack,
stripWhitespace,
nextSibling
Expand All @@ -119,7 +117,6 @@ export default class EachBlock extends Node {
build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const { generator } = this;
Expand Down Expand Up @@ -238,12 +235,12 @@ export default class EachBlock extends Node {
}

this.children.forEach((child: Node) => {
child.build(this._block, this._state, elementStack, componentStack);
child.build(this._block, this._state, componentStack);
});

if (this.else) {
this.else.children.forEach((child: Node) => {
child.build(this.else._block, this.else._state, elementStack, componentStack);
child.build(this.else._block, this.else._state, componentStack);
});
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/generators/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default class Element extends Node {
block: Block,
state: State,
inEachBlock: boolean,
elementStack: Node[],
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
Expand Down Expand Up @@ -156,18 +155,17 @@ export default class Element extends Node {
allUsedContexts: [],
});

this.generator.stylesheet.apply(this, elementStack);
this.generator.stylesheet.apply(this);

if (this.children.length) {
if (this.name === 'pre' || this.name === 'textarea') stripWhitespace = false;
this.initChildren(block, this._state, inEachBlock, elementStack.concat(this), componentStack, stripWhitespace, nextSibling);
this.initChildren(block, this._state, inEachBlock, componentStack, stripWhitespace, nextSibling);
}
}

build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const { generator } = this;
Expand Down Expand Up @@ -240,7 +238,7 @@ export default class Element extends Node {
}
} else {
this.children.forEach((child: Node) => {
child.build(block, childState, elementStack.concat(this), componentStack);
child.build(block, childState, componentStack);
});
}

Expand Down
15 changes: 6 additions & 9 deletions src/generators/nodes/Fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ export default class Fragment extends Node {
state: State;
children: Node[];

init(
namespace: string
) {
init() {
this.block = new Block({
generator: this.generator,
name: '@create_main_fragment',
Expand All @@ -34,17 +32,16 @@ export default class Fragment extends Node {
});

this.generator.blocks.push(this.block);
this.initChildren(this.block, this.state, false, [], [], true, null);
this.initChildren(this.block, this.state, false, [], true, null);

this.block.hasUpdateMethod = true;
}

build(
block: Block,
state: State
) {
build() {
this.init();

this.children.forEach(child => {
child.build(block, state, [], []);
child.build(this.block, this.state, []);
});
}
}
17 changes: 6 additions & 11 deletions src/generators/nodes/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default class IfBlock extends Node {
block: Block,
state: State,
inEachBlock: boolean,
elementStack: Node[],
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
Expand All @@ -54,7 +53,7 @@ export default class IfBlock extends Node {
node._state = state.child();

blocks.push(node._block);
node.initChildren(node._block, node._state, inEachBlock, elementStack, componentStack, stripWhitespace, nextSibling);
node.initChildren(node._block, node._state, inEachBlock, componentStack, stripWhitespace, nextSibling);

if (node._block.dependencies.size > 0) {
dynamic = true;
Expand All @@ -79,7 +78,6 @@ export default class IfBlock extends Node {
node.else._block,
node.else._state,
inEachBlock,
elementStack,
componentStack,
stripWhitespace,
nextSibling
Expand All @@ -106,7 +104,6 @@ export default class IfBlock extends Node {
build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const name = this.var;
Expand All @@ -117,7 +114,7 @@ export default class IfBlock extends Node {
: (this.next && this.next.var) || 'null';
const params = block.params.join(', ');

const branches = getBranches(this.generator, block, state, this, elementStack, componentStack);
const branches = getBranches(this.generator, block, state, this, componentStack);

const hasElse = isElseBranch(branches[branches.length - 1]);
const if_name = hasElse ? '' : `if (${name}) `;
Expand Down Expand Up @@ -173,7 +170,6 @@ function getBranches(
block: Block,
state: State,
node: Node,
elementStack: Node[],
componentStack: Node[]
) {
block.contextualise(node.expression); // TODO remove
Expand All @@ -188,11 +184,11 @@ function getBranches(
},
];

visitChildren(generator, block, state, node, elementStack, componentStack);
visitChildren(generator, block, state, node, componentStack);

if (isElseIf(node.else)) {
branches.push(
...getBranches(generator, block, state, node.else.children[0], elementStack, componentStack)
...getBranches(generator, block, state, node.else.children[0], componentStack)
);
} else {
branches.push({
Expand All @@ -204,7 +200,7 @@ function getBranches(
});

if (node.else) {
visitChildren(generator, block, state, node.else, elementStack, componentStack);
visitChildren(generator, block, state, node.else, componentStack);
}
}

Expand All @@ -216,11 +212,10 @@ function visitChildren(
block: Block,
state: State,
node: Node,
elementStack: Node[],
componentStack: Node[]
) {
node.children.forEach((child: Node) => {
child.build(node._block, node._state, elementStack, componentStack);
child.build(node._block, node._state, componentStack);
});
}

Expand Down
1 change: 0 additions & 1 deletion src/generators/nodes/MustacheTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default class MustacheTag extends Tag {
build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const { init } = this.renameThisMethod(
Expand Down
1 change: 0 additions & 1 deletion src/generators/nodes/RawMustacheTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default class RawMustacheTag extends Tag {
build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const name = this.var;
Expand Down
6 changes: 2 additions & 4 deletions src/generators/nodes/Slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export default class Slot extends Element {
block: Block,
state: State,
inEachBlock: boolean,
elementStack: Node[],
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
Expand All @@ -35,14 +34,13 @@ export default class Slot extends Element {
});

if (this.children.length) {
this.initChildren(block, this._state, inEachBlock, elementStack.concat(this), componentStack, stripWhitespace, nextSibling);
this.initChildren(block, this._state, inEachBlock, componentStack, stripWhitespace, nextSibling);
}
}

build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
const { generator } = this;
Expand Down Expand Up @@ -74,7 +72,7 @@ export default class Slot extends Element {
block.builders.destroy.pushCondition(`!${content_name}`);

this.children.forEach((child: Node) => {
child.build(block, state, elementStack, componentStack);
child.build(block, state, componentStack);
});

block.builders.create.popCondition();
Expand Down
1 change: 0 additions & 1 deletion src/generators/nodes/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class Text extends Node {
build(
block: Block,
state: State,
elementStack: Node[],
componentStack: Node[]
) {
if (this.shouldSkip) return;
Expand Down
Loading