Skip to content

Commit

Permalink
indicate if element is svg
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Mar 18, 2017
1 parent 7dba0f1 commit 3a2c6a4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@
nodeName = node.__moon__nodeName__ || node.nodeName.toLowerCase();
}

var isSVG = node instanceof SVGElement || vnode.meta.isSVG;

if (!node && vnode) {
// No Node, create a node
var newNode = createNodeFromVNode(vnode, instance);
Expand Down Expand Up @@ -866,6 +868,7 @@
};

var HTML_ELEMENTS = ["area", "base", "br", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
var SVG_ELEMENTS = ["svg", "animate", "circle", "clippath", "cursor", "defs", "desc", "ellipse", "filter", "font-face", "foreignObject", "g", "glyph", "image", "line", "marker", "mask", "missing-glyph", "path", "pattern", "polygon", "polyline", "rect", "switch", "symbol", "text", "textpath", "tspan", "use", "view"];

var createParseNode = function (type, props, children) {
return {
Expand Down Expand Up @@ -907,6 +910,11 @@
// Exit Start Tag
increment(4);

// If it is an svg element, let code generator know
if (SVG_ELEMENTS.indexOf(node.type) !== -1) {
node.isSVG = true;
}

// If it's self closing, return it here
if (HTML_ELEMENTS.indexOf(node.type) !== -1) {
return node;
Expand Down Expand Up @@ -1101,6 +1109,9 @@
// Recursively generate code for children
if (!el.meta) {
el.meta = defaultMetadata();
if (el.isSVG) {
el.meta.isSVG = true;
}
}
el.props = {
attrs: el.props
Expand Down
2 changes: 1 addition & 1 deletion dist/moon.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/compiler/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ var generateEl = function(el) {
// Recursively generate code for children
if(!el.meta) {
el.meta = defaultMetadata();
if(el.isSVG) {
el.meta.isSVG = true;
}
}
el.props = {
attrs: el.props
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var parse = function(tokens) {
}

var HTML_ELEMENTS = ["area","base","br","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"];
var SVG_ELEMENTS = ["svg","animate","circle","clippath","cursor","defs","desc","ellipse","filter","font-face","foreignObject","g","glyph","image","line","marker","mask","missing-glyph","path","pattern","polygon","polyline","rect","switch","symbol","text","textpath","tspan","use","view"];

var createParseNode = function(type, props, children) {
return {
Expand Down Expand Up @@ -61,6 +62,11 @@ var walk = function(state) {
// Exit Start Tag
increment(4);

// If it is an svg element, let code generator know
if(SVG_ELEMENTS.indexOf(node.type) !== -1) {
node.isSVG = true;
}

// If it's self closing, return it here
if(HTML_ELEMENTS.indexOf(node.type) !== -1) {
return node;
Expand Down
2 changes: 2 additions & 0 deletions src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ var diff = function(node, vnode, parent, instance) {
nodeName = node.__moon__nodeName__ || node.nodeName.toLowerCase();
}

var isSVG = node instanceof SVGElement || vnode.meta.isSVG;

if(!node && vnode) {
// No Node, create a node
var newNode = createNodeFromVNode(vnode, instance);
Expand Down

0 comments on commit 3a2c6a4

Please sign in to comment.