From 228a7808ac9014fe79f8d4400283cd1f98ae5011 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 1 Sep 2017 17:25:44 -0400 Subject: [PATCH 1/4] optimize style attributes --- .../dom/visitors/Element/Attribute.ts | 11 +- .../dom/visitors/Element/StyleAttribute.ts | 177 ++++++++++++++ src/utils/getExpressionPrecedence.ts | 53 +++++ test/js/index.js | 2 +- .../expected-bundle.js | 217 ++++++++++++++++++ .../expected.js | 64 ++++++ .../input.html | 1 + .../inline-style-optimized/expected-bundle.js | 212 +++++++++++++++++ .../inline-style-optimized/expected.js | 59 +++++ .../samples/inline-style-optimized/input.html | 1 + 10 files changed, 795 insertions(+), 2 deletions(-) create mode 100644 src/generators/dom/visitors/Element/StyleAttribute.ts create mode 100644 src/utils/getExpressionPrecedence.ts create mode 100644 test/js/samples/inline-style-optimized-multiple/expected-bundle.js create mode 100644 test/js/samples/inline-style-optimized-multiple/expected.js create mode 100644 test/js/samples/inline-style-optimized-multiple/input.html create mode 100644 test/js/samples/inline-style-optimized/expected-bundle.js create mode 100644 test/js/samples/inline-style-optimized/expected.js create mode 100644 test/js/samples/inline-style-optimized/input.html diff --git a/src/generators/dom/visitors/Element/Attribute.ts b/src/generators/dom/visitors/Element/Attribute.ts index 042c1abdce..47bbea808f 100644 --- a/src/generators/dom/visitors/Element/Attribute.ts +++ b/src/generators/dom/visitors/Element/Attribute.ts @@ -1,5 +1,6 @@ import attributeLookup from './lookup'; import deindent from '../../../../utils/deindent'; +import visitStyleAttribute, { optimizeStyle } from './StyleAttribute'; import { stringify } from '../../../../utils/stringify'; import getStaticAttributeValue from '../../../shared/getStaticAttributeValue'; import { DomGenerator } from '../../index'; @@ -16,6 +17,14 @@ export default function visitAttribute( ) { const name = attribute.name; + if (name === 'style') { + const styleProps = optimizeStyle(attribute.value); + if (styleProps) { + visitStyleAttribute(generator, block, state, node, attribute, styleProps); + return; + } + } + let metadata = state.namespace ? null : attributeLookup[name]; if (metadata && metadata.appliesTo && !~metadata.appliesTo.indexOf(node.name)) metadata = null; @@ -211,4 +220,4 @@ export default function visitAttribute( block.builders.hydrate.addLine(updateValue); if (isDynamic) block.builders.update.addLine(updateValue); } -} +} \ No newline at end of file diff --git a/src/generators/dom/visitors/Element/StyleAttribute.ts b/src/generators/dom/visitors/Element/StyleAttribute.ts new file mode 100644 index 0000000000..da833ba8f4 --- /dev/null +++ b/src/generators/dom/visitors/Element/StyleAttribute.ts @@ -0,0 +1,177 @@ +import attributeLookup from './lookup'; +import deindent from '../../../../utils/deindent'; +import { stringify } from '../../../../utils/stringify'; +import getExpressionPrecedence from '../../../../utils/getExpressionPrecedence'; +import getStaticAttributeValue from '../../../shared/getStaticAttributeValue'; +import { DomGenerator } from '../../index'; +import Block from '../../Block'; +import { Node } from '../../../../interfaces'; +import { State } from '../../interfaces'; + +export interface StyleProp { + key: string; + value: Node[]; +} + +export default function visitStyleAttribute( + generator: DomGenerator, + block: Block, + state: State, + node: Node, + attribute: Node, + styleProps: StyleProp[] +) { + styleProps.forEach((prop: StyleProp) => { + let value; + + if (isDynamic(prop.value)) { + const allDependencies = new Set(); + let shouldCache; + let hasChangeableIndex; + + value = + ((prop.value.length === 1 || prop.value[0].type === 'Text') ? '' : `"" + `) + + prop.value + .map((chunk: Node) => { + if (chunk.type === 'Text') { + return stringify(chunk.data); + } else { + const { snippet, dependencies, indexes } = block.contextualise(chunk.expression); + + if (Array.from(indexes).some(index => block.changeableIndexes.get(index))) { + hasChangeableIndex = true; + } + + dependencies.forEach(d => { + allDependencies.add(d); + }); + + return getExpressionPrecedence(chunk.expression) <= 13 ? `( ${snippet} )` : snippet; + } + }) + .join(' + '); + + if (allDependencies.size || hasChangeableIndex) { + const dependencies = Array.from(allDependencies); + const condition = ( + ( block.hasOutroMethod ? `#outroing || ` : '' ) + + dependencies.map(dependency => `changed.${dependency}`).join(' || ') + ); + + block.builders.update.addConditional( + condition, + `${node.var}.style.setProperty('${prop.key}', ${value});` + ); + } + } else { + value = stringify(prop.value[0].data); + } + + block.builders.hydrate.addLine( + `${node.var}.style.setProperty('${prop.key}', ${value});` + ); + }); +} + +export function optimizeStyle(value: Node[]) { + let expectingKey = true; + let i = 0; + + const props: { key: string, value: Node[] }[] = []; + let chunks = value.slice(); + + while (chunks.length) { + const chunk = chunks[0]; + + if (chunk.type !== 'Text') return null; + + const keyMatch = /^\s*([\w-]+):\s*/.exec(chunk.data); + if (!keyMatch) return null; + + const key = keyMatch[1]; + + const offset = keyMatch.index + keyMatch[0].length; + const remainingData = chunk.data.slice(offset); + + if (remainingData) { + chunks[0] = { + start: chunk.start + offset, + end: chunk.end, + type: 'Text', + data: remainingData + }; + } else { + chunks.shift(); + } + + const result = getStyleValue(chunks); + if (!result) return null; + + props.push({ key, value: result.value }); + chunks = result.chunks; + } + + return props; +} + +function getStyleValue(chunks: Node[]) { + const value: Node[] = []; + + let inUrl = false; + + while (chunks.length) { + const chunk = chunks[0]; + + if (chunk.type === 'Text') { + // TODO annoying special case — urls can contain semicolons + + let index = chunk.data.indexOf(';'); + + if (index === -1) { + value.push(chunk); + chunks.shift(); + } + + else { + if (index > 0) { + value.push({ + type: 'Text', + start: chunk.start, + end: chunk.start + index, + data: chunk.data.slice(0, index) + }); + } + + while (/[;\s]/.test(chunk.data[index])) index += 1; + + const remainingData = chunk.data.slice(index); + + if (remainingData) { + chunks[0] = { + start: chunk.start + index, + end: chunk.end, + type: 'Text', + data: remainingData + }; + } else { + chunks.shift(); + } + + break; + } + } + + else { + value.push(chunks.shift()); + } + } + + return { + chunks, + value + }; +} + +function isDynamic(value: Node[]) { + return value.length > 1 || value[0].type !== 'Text'; +} \ No newline at end of file diff --git a/src/utils/getExpressionPrecedence.ts b/src/utils/getExpressionPrecedence.ts new file mode 100644 index 0000000000..3e136246ba --- /dev/null +++ b/src/utils/getExpressionPrecedence.ts @@ -0,0 +1,53 @@ +import { Node } from '../interfaces'; + +const binaryOperators: Record = { + '**': 15, + '*': 14, + '/': 14, + '%': 14, + '+': 13, + '-': 13, + '<<': 12, + '>>': 12, + '>>>': 12, + '<': 11, + '<=': 11, + '>': 11, + '>=': 11, + 'in': 11, + 'instanceof': 11, + '==': 10, + '!=': 10, + '===': 10, + '!==': 10, + '&': 9, + '^': 8, + '|': 7 +}; + +const logicalOperators: Record = { + '&&': 6, + '||': 5 +}; + +const precedence: Record number> = { + Literal: () => 21, + Identifier: () => 21, + ParenthesizedExpression: () => 20, + MemberExpression: () => 19, + NewExpression: () => 19, // can be 18 (if no args) but makes no practical difference + CallExpression: () => 19, + UpdateExpression: () => 17, + UnaryExpression: () => 16, + BinaryExpression: (expression: Node) => binaryOperators[expression.operator], + LogicalExpression: (expression: Node) => logicalOperators[expression.operator], + ConditionalExpression: () => 4, + AssignmentExpression: () => 3, + YieldExpression: () => 2, + SpreadElement: () => 1, + SequenceExpression: () => 0 +}; + +export default function getExpressionPrecedence(expression: Node) { + return expression.type in precedence ? precedence[expression.type](expression) : 0; +} \ No newline at end of file diff --git a/test/js/index.js b/test/js/index.js index aa55e7ebad..581df93dd8 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -39,7 +39,7 @@ describe("js", () => { fs.writeFileSync(`${dir}/_actual.js`, actual); return rollup({ - entry: `${dir}/_actual.js`, + input: `${dir}/_actual.js`, plugins: [ { resolveId(importee, importer) { diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js new file mode 100644 index 0000000000..37abe9d46f --- /dev/null +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -0,0 +1,217 @@ +function noop() {} + +function assign(target) { + var k, + source, + i = 1, + len = arguments.length; + for (; i < len; i++) { + source = arguments[i]; + for (k in source) target[k] = source[k]; + } + + return target; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = this._state = null; +} + +function differs(a, b) { + return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + var callbacks = group[key]; + if (!callbacks) continue; + + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; + + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; + } + } +} + +function get(key) { + return key ? this._state[key] : this._state; +} + +function fire(eventName, data) { + var handlers = + eventName in this._handlers && this._handlers[eventName].slice(); + if (!handlers) return; + + for (var i = 0; i < handlers.length; i += 1) { + handlers[i].call(this, data); + } +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (group[key] || (group[key] = [])).push(callback); + + if (!options || options.init !== false) { + callback.__calling = true; + callback.call(this, this._state[key]); + callback.__calling = false; + } + + return { + cancel: function() { + var index = group[key].indexOf(callback); + if (~index) group[key].splice(index, 1); + } + }; +} + +function on(eventName, handler) { + if (eventName === 'teardown') return this.on('destroy', handler); + + var handlers = this._handlers[eventName] || (this._handlers[eventName] = []); + handlers.push(handler); + + return { + cancel: function() { + var index = handlers.indexOf(handler); + if (~index) handlers.splice(index, 1); + } + }; +} + +function set(newState) { + this._set(assign({}, newState)); + if (this._root._lock) return; + this._root._lock = true; + callAll(this._root._beforecreate); + callAll(this._root._oncreate); + callAll(this._root._aftercreate); + this._root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + if (this._bind) this._bind(changed, this._state); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + +function callAll(fns) { + while (fns && fns.length) fns.pop()(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set +}; + +function create_main_fragment ( state, component ) { + var div; + + return { + create: function () { + div = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.setProperty('color', state.color); + div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.color ) { + div.style.setProperty('color', state.color); + } + + if ( changed.x || changed.y ) { + div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + } + }, + + unmount: function () { + detachNode( div ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js new file mode 100644 index 0000000000..49cd174c7e --- /dev/null +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -0,0 +1,64 @@ +import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment ( state, component ) { + var div; + + return { + create: function () { + div = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.setProperty('color', state.color); + div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.color ) { + div.style.setProperty('color', state.color); + } + + if ( changed.x || changed.y ) { + div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + } + }, + + unmount: function () { + detachNode( div ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-multiple/input.html b/test/js/samples/inline-style-optimized-multiple/input.html new file mode 100644 index 0000000000..92d9cb805d --- /dev/null +++ b/test/js/samples/inline-style-optimized-multiple/input.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js new file mode 100644 index 0000000000..5ba7797e47 --- /dev/null +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -0,0 +1,212 @@ +function noop() {} + +function assign(target) { + var k, + source, + i = 1, + len = arguments.length; + for (; i < len; i++) { + source = arguments[i]; + for (k in source) target[k] = source[k]; + } + + return target; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = this._state = null; +} + +function differs(a, b) { + return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + var callbacks = group[key]; + if (!callbacks) continue; + + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; + + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; + } + } +} + +function get(key) { + return key ? this._state[key] : this._state; +} + +function fire(eventName, data) { + var handlers = + eventName in this._handlers && this._handlers[eventName].slice(); + if (!handlers) return; + + for (var i = 0; i < handlers.length; i += 1) { + handlers[i].call(this, data); + } +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (group[key] || (group[key] = [])).push(callback); + + if (!options || options.init !== false) { + callback.__calling = true; + callback.call(this, this._state[key]); + callback.__calling = false; + } + + return { + cancel: function() { + var index = group[key].indexOf(callback); + if (~index) group[key].splice(index, 1); + } + }; +} + +function on(eventName, handler) { + if (eventName === 'teardown') return this.on('destroy', handler); + + var handlers = this._handlers[eventName] || (this._handlers[eventName] = []); + handlers.push(handler); + + return { + cancel: function() { + var index = handlers.indexOf(handler); + if (~index) handlers.splice(index, 1); + } + }; +} + +function set(newState) { + this._set(assign({}, newState)); + if (this._root._lock) return; + this._root._lock = true; + callAll(this._root._beforecreate); + callAll(this._root._oncreate); + callAll(this._root._aftercreate); + this._root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + if (this._bind) this._bind(changed, this._state); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + +function callAll(fns) { + while (fns && fns.length) fns.pop()(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set +}; + +function create_main_fragment ( state, component ) { + var div; + + return { + create: function () { + div = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.setProperty('color', state.color); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.color ) { + div.style.setProperty('color', state.color); + } + }, + + unmount: function () { + detachNode( div ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js new file mode 100644 index 0000000000..5c9883775e --- /dev/null +++ b/test/js/samples/inline-style-optimized/expected.js @@ -0,0 +1,59 @@ +import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment ( state, component ) { + var div; + + return { + create: function () { + div = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.setProperty('color', state.color); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.color ) { + div.style.setProperty('color', state.color); + } + }, + + unmount: function () { + detachNode( div ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/input.html b/test/js/samples/inline-style-optimized/input.html new file mode 100644 index 0000000000..ff7d95fb6e --- /dev/null +++ b/test/js/samples/inline-style-optimized/input.html @@ -0,0 +1 @@ +
\ No newline at end of file From d54d00cac1187737e3f875dd0e8d6516694b9068 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 2 Sep 2017 12:59:00 -0400 Subject: [PATCH 2/4] handle url(...) and quoted values --- .../dom/visitors/Element/StyleAttribute.ts | 71 +++--- .../expected-bundle.js | 212 ++++++++++++++++ .../inline-style-optimized-url/expected.js | 59 +++++ .../inline-style-optimized-url/input.html | 1 + .../expected-bundle.js | 227 ++++++++++++++++++ .../inline-style-unoptimized/expected.js | 70 ++++++ .../inline-style-unoptimized/input.html | 2 + 7 files changed, 612 insertions(+), 30 deletions(-) create mode 100644 test/js/samples/inline-style-optimized-url/expected-bundle.js create mode 100644 test/js/samples/inline-style-optimized-url/expected.js create mode 100644 test/js/samples/inline-style-optimized-url/input.html create mode 100644 test/js/samples/inline-style-unoptimized/expected-bundle.js create mode 100644 test/js/samples/inline-style-unoptimized/expected.js create mode 100644 test/js/samples/inline-style-unoptimized/input.html diff --git a/src/generators/dom/visitors/Element/StyleAttribute.ts b/src/generators/dom/visitors/Element/StyleAttribute.ts index da833ba8f4..2ca0618eb2 100644 --- a/src/generators/dom/visitors/Element/StyleAttribute.ts +++ b/src/generators/dom/visitors/Element/StyleAttribute.ts @@ -118,51 +118,62 @@ function getStyleValue(chunks: Node[]) { const value: Node[] = []; let inUrl = false; + let quoteMark = null; + let escaped = false; while (chunks.length) { - const chunk = chunks[0]; + const chunk = chunks.shift(); if (chunk.type === 'Text') { - // TODO annoying special case — urls can contain semicolons - - let index = chunk.data.indexOf(';'); + let c = 0; + while (c < chunk.data.length) { + const char = chunk.data[c]; + + if (escaped) { + escaped = false; + } else if (char === '\\') { + escaped = true; + } else if (char === quoteMark) { + quoteMark === null; + } else if (char === '"' || char === "'") { + quoteMark = char; + } else if (char === ')' && inUrl) { + inUrl = false; + } else if (char === 'u' && chunk.data.slice(c, c + 4) === 'url(') { + inUrl = true; + } else if (char === ';' && !inUrl && !quoteMark) { + break; + } - if (index === -1) { - value.push(chunk); - chunks.shift(); + c += 1; } - else { - if (index > 0) { - value.push({ - type: 'Text', - start: chunk.start, - end: chunk.start + index, - data: chunk.data.slice(0, index) - }); - } - - while (/[;\s]/.test(chunk.data[index])) index += 1; + if (c > 0) { + value.push({ + type: 'Text', + start: chunk.start, + end: chunk.start + c, + data: chunk.data.slice(0, c) + }); + } - const remainingData = chunk.data.slice(index); + while (/[;\s]/.test(chunk.data[c])) c += 1; + const remainingData = chunk.data.slice(c); - if (remainingData) { - chunks[0] = { - start: chunk.start + index, - end: chunk.end, - type: 'Text', - data: remainingData - }; - } else { - chunks.shift(); - } + if (remainingData) { + chunks.unshift({ + start: chunk.start + c, + end: chunk.end, + type: 'Text', + data: remainingData + }); break; } } else { - value.push(chunks.shift()); + value.push(chunk); } } diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js new file mode 100644 index 0000000000..45eb18fb0a --- /dev/null +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -0,0 +1,212 @@ +function noop() {} + +function assign(target) { + var k, + source, + i = 1, + len = arguments.length; + for (; i < len; i++) { + source = arguments[i]; + for (k in source) target[k] = source[k]; + } + + return target; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = this._state = null; +} + +function differs(a, b) { + return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + var callbacks = group[key]; + if (!callbacks) continue; + + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; + + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; + } + } +} + +function get(key) { + return key ? this._state[key] : this._state; +} + +function fire(eventName, data) { + var handlers = + eventName in this._handlers && this._handlers[eventName].slice(); + if (!handlers) return; + + for (var i = 0; i < handlers.length; i += 1) { + handlers[i].call(this, data); + } +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (group[key] || (group[key] = [])).push(callback); + + if (!options || options.init !== false) { + callback.__calling = true; + callback.call(this, this._state[key]); + callback.__calling = false; + } + + return { + cancel: function() { + var index = group[key].indexOf(callback); + if (~index) group[key].splice(index, 1); + } + }; +} + +function on(eventName, handler) { + if (eventName === 'teardown') return this.on('destroy', handler); + + var handlers = this._handlers[eventName] || (this._handlers[eventName] = []); + handlers.push(handler); + + return { + cancel: function() { + var index = handlers.indexOf(handler); + if (~index) handlers.splice(index, 1); + } + }; +} + +function set(newState) { + this._set(assign({}, newState)); + if (this._root._lock) return; + this._root._lock = true; + callAll(this._root._beforecreate); + callAll(this._root._oncreate); + callAll(this._root._aftercreate); + this._root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + if (this._bind) this._bind(changed, this._state); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + +function callAll(fns) { + while (fns && fns.length) fns.pop()(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set +}; + +function create_main_fragment ( state, component ) { + var div; + + return { + create: function () { + div = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.data ) { + div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + } + }, + + unmount: function () { + detachNode( div ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js new file mode 100644 index 0000000000..bd5439dbf6 --- /dev/null +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -0,0 +1,59 @@ +import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment ( state, component ) { + var div; + + return { + create: function () { + div = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.data ) { + div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + } + }, + + unmount: function () { + detachNode( div ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-url/input.html b/test/js/samples/inline-style-optimized-url/input.html new file mode 100644 index 0000000000..7e3b2928eb --- /dev/null +++ b/test/js/samples/inline-style-optimized-url/input.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js new file mode 100644 index 0000000000..f463764157 --- /dev/null +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -0,0 +1,227 @@ +function noop() {} + +function assign(target) { + var k, + source, + i = 1, + len = arguments.length; + for (; i < len; i++) { + source = arguments[i]; + for (k in source) target[k] = source[k]; + } + + return target; +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.unmount(); + this._fragment.destroy(); + this._fragment = this._state = null; +} + +function differs(a, b) { + return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + var callbacks = group[key]; + if (!callbacks) continue; + + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; + + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; + } + } +} + +function get(key) { + return key ? this._state[key] : this._state; +} + +function fire(eventName, data) { + var handlers = + eventName in this._handlers && this._handlers[eventName].slice(); + if (!handlers) return; + + for (var i = 0; i < handlers.length; i += 1) { + handlers[i].call(this, data); + } +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (group[key] || (group[key] = [])).push(callback); + + if (!options || options.init !== false) { + callback.__calling = true; + callback.call(this, this._state[key]); + callback.__calling = false; + } + + return { + cancel: function() { + var index = group[key].indexOf(callback); + if (~index) group[key].splice(index, 1); + } + }; +} + +function on(eventName, handler) { + if (eventName === 'teardown') return this.on('destroy', handler); + + var handlers = this._handlers[eventName] || (this._handlers[eventName] = []); + handlers.push(handler); + + return { + cancel: function() { + var index = handlers.indexOf(handler); + if (~index) handlers.splice(index, 1); + } + }; +} + +function set(newState) { + this._set(assign({}, newState)); + if (this._root._lock) return; + this._root._lock = true; + callAll(this._root._beforecreate); + callAll(this._root._oncreate); + callAll(this._root._aftercreate); + this._root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + if (this._bind) this._bind(changed, this._state); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + +function callAll(fns) { + while (fns && fns.length) fns.pop()(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set +}; + +function create_main_fragment ( state, component ) { + var div, text, div_1, div_1_style_value; + + return { + create: function () { + div = createElement( 'div' ); + text = createText( "\n" ); + div_1 = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.cssText = state.style; + div_1.style.cssText = div_1_style_value = "" + ( state.key ) + ": " + ( state.value ); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + insertNode( text, target, anchor ); + insertNode( div_1, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.style ) { + div.style.cssText = state.style; + } + + if ( ( changed.key || changed.value ) && div_1_style_value !== ( div_1_style_value = "" + ( state.key ) + ": " + ( state.value ) ) ) { + div_1.style.cssText = div_1_style_value; + } + }, + + unmount: function () { + detachNode( div ); + detachNode( text ); + detachNode( div_1 ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js new file mode 100644 index 0000000000..74f9ddca2a --- /dev/null +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -0,0 +1,70 @@ +import { assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; + +function create_main_fragment ( state, component ) { + var div, text, div_1, div_1_style_value; + + return { + create: function () { + div = createElement( 'div' ); + text = createText( "\n" ); + div_1 = createElement( 'div' ); + this.hydrate(); + }, + + hydrate: function ( nodes ) { + div.style.cssText = state.style; + div_1.style.cssText = div_1_style_value = "" + ( state.key ) + ": " + ( state.value ); + }, + + mount: function ( target, anchor ) { + insertNode( div, target, anchor ); + insertNode( text, target, anchor ); + insertNode( div_1, target, anchor ); + }, + + update: function ( changed, state ) { + if ( changed.style ) { + div.style.cssText = state.style; + } + + if ( ( changed.key || changed.value ) && div_1_style_value !== ( div_1_style_value = "" + ( state.key ) + ": " + ( state.value ) ) ) { + div_1.style.cssText = div_1_style_value; + } + }, + + unmount: function () { + detachNode( div ); + detachNode( text ); + detachNode( div_1 ); + }, + + destroy: noop + }; +} + +function SvelteComponent ( options ) { + this.options = options; + this._state = options.data || {}; + + this._observers = { + pre: Object.create( null ), + post: Object.create( null ) + }; + + this._handlers = Object.create( null ); + + this._root = options._root || this; + this._yield = options._yield; + this._bind = options._bind; + + this._fragment = create_main_fragment( this._state, this ); + + if ( options.target ) { + this._fragment.create(); + this._fragment.mount( options.target, options.anchor || null ); + } +} + +assign( SvelteComponent.prototype, proto ); + +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/input.html b/test/js/samples/inline-style-unoptimized/input.html new file mode 100644 index 0000000000..87e4592bfd --- /dev/null +++ b/test/js/samples/inline-style-unoptimized/input.html @@ -0,0 +1,2 @@ +
+
\ No newline at end of file From 186b770ef4fe97fef6826df1a5657dcf1e7f70c2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 3 Sep 2017 08:30:08 -0400 Subject: [PATCH 3/4] use helper for setting styles --- .../dom/visitors/Element/StyleAttribute.ts | 4 ++-- src/shared/dom.js | 4 ++++ .../expected-bundle.js | 12 ++++++++---- .../inline-style-optimized-multiple/expected.js | 10 +++++----- .../inline-style-optimized-url/expected-bundle.js | 8 ++++++-- .../samples/inline-style-optimized-url/expected.js | 6 +++--- .../inline-style-optimized/expected-bundle.js | 8 ++++++-- test/js/samples/inline-style-optimized/expected.js | 6 +++--- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/generators/dom/visitors/Element/StyleAttribute.ts b/src/generators/dom/visitors/Element/StyleAttribute.ts index 2ca0618eb2..b821ed4719 100644 --- a/src/generators/dom/visitors/Element/StyleAttribute.ts +++ b/src/generators/dom/visitors/Element/StyleAttribute.ts @@ -60,7 +60,7 @@ export default function visitStyleAttribute( block.builders.update.addConditional( condition, - `${node.var}.style.setProperty('${prop.key}', ${value});` + `@setStyle(${node.var}, '${prop.key}', ${value});` ); } } else { @@ -68,7 +68,7 @@ export default function visitStyleAttribute( } block.builders.hydrate.addLine( - `${node.var}.style.setProperty('${prop.key}', ${value});` + `@setStyle(${node.var}, '${prop.key}', ${value});` ); }); } diff --git a/src/shared/dom.js b/src/shared/dom.js index 0372d96fdc..e3b1676e1c 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -137,4 +137,8 @@ export function setInputType(input, type) { try { input.type = type; } catch (e) {} +} + +export function setStyle(node, key, value) { + node.style.setProperty(key, value); } \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js index 37abe9d46f..c9f7b3729a 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -25,6 +25,10 @@ function createElement(name) { return document.createElement(name); } +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -163,8 +167,8 @@ function create_main_fragment ( state, component ) { }, hydrate: function ( nodes ) { - div.style.setProperty('color', state.color); - div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + setStyle(div, 'color', state.color); + setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)"); }, mount: function ( target, anchor ) { @@ -173,11 +177,11 @@ function create_main_fragment ( state, component ) { update: function ( changed, state ) { if ( changed.color ) { - div.style.setProperty('color', state.color); + setStyle(div, 'color', state.color); } if ( changed.x || changed.y ) { - div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)"); } }, diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 49cd174c7e..3d48ec09a8 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment ( state, component ) { var div; @@ -10,8 +10,8 @@ function create_main_fragment ( state, component ) { }, hydrate: function ( nodes ) { - div.style.setProperty('color', state.color); - div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + setStyle(div, 'color', state.color); + setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)"); }, mount: function ( target, anchor ) { @@ -20,11 +20,11 @@ function create_main_fragment ( state, component ) { update: function ( changed, state ) { if ( changed.color ) { - div.style.setProperty('color', state.color); + setStyle(div, 'color', state.color); } if ( changed.x || changed.y ) { - div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)"); + setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)"); } }, diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js index 45eb18fb0a..e3793b4fe1 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -25,6 +25,10 @@ function createElement(name) { return document.createElement(name); } +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -163,7 +167,7 @@ function create_main_fragment ( state, component ) { }, hydrate: function ( nodes ) { - div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")"); }, mount: function ( target, anchor ) { @@ -172,7 +176,7 @@ function create_main_fragment ( state, component ) { update: function ( changed, state ) { if ( changed.data ) { - div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")"); } }, diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index bd5439dbf6..b02e794bb8 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment ( state, component ) { var div; @@ -10,7 +10,7 @@ function create_main_fragment ( state, component ) { }, hydrate: function ( nodes ) { - div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")"); }, mount: function ( target, anchor ) { @@ -19,7 +19,7 @@ function create_main_fragment ( state, component ) { update: function ( changed, state ) { if ( changed.data ) { - div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")"); + setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")"); } }, diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 5ba7797e47..98713a9e1b 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -25,6 +25,10 @@ function createElement(name) { return document.createElement(name); } +function setStyle(node, key, value) { + node.style.setProperty(key, value); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -163,7 +167,7 @@ function create_main_fragment ( state, component ) { }, hydrate: function ( nodes ) { - div.style.setProperty('color', state.color); + setStyle(div, 'color', state.color); }, mount: function ( target, anchor ) { @@ -172,7 +176,7 @@ function create_main_fragment ( state, component ) { update: function ( changed, state ) { if ( changed.color ) { - div.style.setProperty('color', state.color); + setStyle(div, 'color', state.color); } }, diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index 5c9883775e..2de1d2b084 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment ( state, component ) { var div; @@ -10,7 +10,7 @@ function create_main_fragment ( state, component ) { }, hydrate: function ( nodes ) { - div.style.setProperty('color', state.color); + setStyle(div, 'color', state.color); }, mount: function ( target, anchor ) { @@ -19,7 +19,7 @@ function create_main_fragment ( state, component ) { update: function ( changed, state ) { if ( changed.color ) { - div.style.setProperty('color', state.color); + setStyle(div, 'color', state.color); } }, From 3ea3f53819bb46d94fd388673d29c74bd9e75600 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 3 Sep 2017 08:35:30 -0400 Subject: [PATCH 4/4] -> v1.36.0 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77c2470c1c..5eb2814712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## 1.36.0 + +* Optimize `style` attributes where possible ([#455](https://github.com/sveltejs/svelte/issues/455)) + ## 1.35.0 * `set` and `get` continue to work until `destroy` is complete ([#788](https://github.com/sveltejs/svelte/issues/788)) diff --git a/package.json b/package.json index c9846fa508..941af0494b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "1.35.0", + "version": "1.36.0", "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", "files": [