diff --git a/package-lock.json b/package-lock.json index 82ea06f559..071f56418a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.0.0-alpha1", + "version": "3.0.0-alpha3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/compile/Component.ts b/src/compile/Component.ts index bf874bbbea..36730ed09e 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -80,7 +80,6 @@ export default class Component { indirectDependencies: Map> = new Map(); template_references: Set = new Set(); - refs: Set = new Set(); file: string; locate: (c: number) => { line: number, column: number }; diff --git a/src/compile/css/Selector.ts b/src/compile/css/Selector.ts index d6323c6efe..a6ee79e181 100644 --- a/src/compile/css/Selector.ts +++ b/src/compile/css/Selector.ts @@ -71,18 +71,6 @@ export default class Selector { break; } - - i = block.selectors.length; - while (i--) { - const selector = block.selectors[i]; - - if (selector.type === 'RefSelector') { - code.overwrite(selector.start, selector.end, `.svelte-ref-${selector.name}`, { - contentOnly: true, - storeName: false - }); - } - } } this.blocks.forEach((block, i) => { @@ -173,15 +161,6 @@ function applySelector(stylesheet: Stylesheet, blocks: Block[], node: Node, stac if (node.name.toLowerCase() !== selector.name.toLowerCase() && selector.name !== '*') return false; } - else if (selector.type === 'RefSelector') { - if (node.ref && node.ref.name === selector.name) { - stylesheet.nodesWithRefCssClass.set(selector.name, node); - toEncapsulate.push({ node, block }); - return true; - } - return; - } - else { // bail. TODO figure out what these could be toEncapsulate.push({ node, block }); diff --git a/src/compile/css/Stylesheet.ts b/src/compile/css/Stylesheet.ts index dcb3fc5a7f..96e959c99d 100644 --- a/src/compile/css/Stylesheet.ts +++ b/src/compile/css/Stylesheet.ts @@ -342,9 +342,6 @@ export default class Stylesheet { this.nodesWithCssClass.forEach((node: Node) => { node.addCssClass(); }); - this.nodesWithRefCssClass.forEach((node: Node, name: String) => { - node.addCssClass(`svelte-ref-${name}`); - }) } render(cssOutputFilename: string, shouldTransformSelectors: boolean) { diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index 391194d004..e626e25148 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -13,7 +13,6 @@ import { namespaces } from '../../utils/namespaces'; import mapChildren from './shared/mapChildren'; import { dimensions } from '../../utils/patterns'; import fuzzymatch from '../../utils/fuzzymatch'; -import Ref from './Ref'; import list from '../../utils/list'; const svg = /^(?:altGlyph|altGlyphDef|altGlyphItem|animate|animateColor|animateMotion|animateTransform|circle|clipPath|color-profile|cursor|defs|desc|discard|ellipse|feBlend|feColorMatrix|feComponentTransfer|feComposite|feConvolveMatrix|feDiffuseLighting|feDisplacementMap|feDistantLight|feDropShadow|feFlood|feFuncA|feFuncB|feFuncG|feFuncR|feGaussianBlur|feImage|feMerge|feMergeNode|feMorphology|feOffset|fePointLight|feSpecularLighting|feSpotLight|feTile|feTurbulence|filter|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|foreignObject|g|glyph|glyphRef|hatch|hatchpath|hkern|image|line|linearGradient|marker|mask|mesh|meshgradient|meshpatch|meshrow|metadata|missing-glyph|mpath|path|pattern|polygon|polyline|radialGradient|rect|set|solidcolor|stop|switch|symbol|text|textPath|tref|tspan|unknown|use|view|vkern)$/; @@ -86,8 +85,6 @@ export default class Element extends Node { outro?: Transition = null; animation?: Animation = null; children: Node[]; - - ref: Ref; namespace: string; constructor(component, parent, scope, info: any) { @@ -181,10 +178,6 @@ export default class Element extends Node { this.animation = new Animation(component, this, scope, node); break; - case 'Ref': - this.ref = new Ref(component, this, scope, node); - break; - default: throw new Error(`Not implemented: ${node.type}`); } @@ -551,7 +544,7 @@ export default class Element extends Node { message: `'${binding.name}' is not a valid binding on void elements like <${this.name}>. Use a wrapper element instead` }); } - } else { + } else if (name !== 'this') { component.error(binding, { code: `invalid-binding`, message: `'${binding.name}' is not a valid binding` diff --git a/src/compile/nodes/InlineComponent.ts b/src/compile/nodes/InlineComponent.ts index 8380ff43cf..1aa07bdfc2 100644 --- a/src/compile/nodes/InlineComponent.ts +++ b/src/compile/nodes/InlineComponent.ts @@ -5,7 +5,6 @@ import Binding from './Binding'; import EventHandler from './EventHandler'; import Expression from './shared/Expression'; import Component from '../Component'; -import Ref from './Ref'; export default class InlineComponent extends Node { type: 'InlineComponent'; @@ -15,7 +14,6 @@ export default class InlineComponent extends Node { bindings: Binding[]; handlers: EventHandler[]; children: Node[]; - ref: Ref; constructor(component: Component, parent, scope, info) { super(component, parent, scope, info); @@ -62,10 +60,6 @@ export default class InlineComponent extends Node { this.handlers.push(new EventHandler(component, this, scope, node)); break; - case 'Ref': - this.ref = new Ref(component, this, scope, node); - break; - case 'Transition': component.error(node, { code: `invalid-transition`, diff --git a/src/compile/nodes/Ref.ts b/src/compile/nodes/Ref.ts deleted file mode 100644 index 57100a8f26..0000000000 --- a/src/compile/nodes/Ref.ts +++ /dev/null @@ -1,31 +0,0 @@ -import Node from './shared/Node'; -import isValidIdentifier from '../../utils/isValidIdentifier'; - -export default class Ref extends Node { - type: 'Ref'; - name: string; - - constructor(component, parent, scope, info) { - super(component, parent, scope, info); - - if (parent.ref) { - component.error({ - code: 'duplicate-refs', - message: `Duplicate refs` - }); - } - - if (!isValidIdentifier(info.name)) { - const suggestion = info.name.replace(/[^_$a-z0-9]/ig, '_').replace(/^\d/, '_$&'); - - component.error(info, { - code: `invalid-reference-name`, - message: `Reference name '${info.name}' is invalid — must be a valid identifier such as ${suggestion}` - }); - } else { - component.refs.add(info.name); - } - - this.name = info.name; - } -} \ No newline at end of file diff --git a/src/compile/render-dom/index.ts b/src/compile/render-dom/index.ts index 0384a4162e..ffc0634e02 100644 --- a/src/compile/render-dom/index.ts +++ b/src/compile/render-dom/index.ts @@ -55,8 +55,6 @@ export default function dom( builder.addBlock(block.toString()); }); - const refs = Array.from(component.refs); - if (options.dev && !options.hydratable) { block.builders.claim.addLine( 'throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");' @@ -87,14 +85,6 @@ export default function dom( ` : null; - const inject_refs = refs.length > 0 - ? deindent` - $$refs => { - ${refs.map(name => `${name} = $$refs.${name};`)} - } - ` - : null; - const body = []; const not_equal = component.options.immutable ? `@not_equal` : `@safe_not_equal`; @@ -307,8 +297,6 @@ export default function dom( if (${Array.from(d.dependencies).map(n => `$$dirty.${n}`).join(' || ')}) ${d.snippet}`)} }; `} - - ${inject_refs && `$$self.$$.inject_refs = ${inject_refs};`} } `); } diff --git a/src/compile/render-dom/wrappers/Element/Binding.ts b/src/compile/render-dom/wrappers/Element/Binding.ts index 318bf8ffe6..6b2f37cfb1 100644 --- a/src/compile/render-dom/wrappers/Element/Binding.ts +++ b/src/compile/render-dom/wrappers/Element/Binding.ts @@ -178,6 +178,10 @@ function getDomUpdater( return null; } + if (binding.node.name === 'this') { + return null; + } + if (node.name === 'select') { return node.getStaticAttributeValue('multiple') === true ? `@selectOptions(${element.var}, ${snippet})` : @@ -259,6 +263,10 @@ function getValueFromDom( const { node } = element; const { name } = binding.node; + if (name === 'this') { + return `$$node`; + } + // + {/if} \ No newline at end of file diff --git a/test/runtime/samples/await-then-catch-event/main.html b/test/runtime/samples/await-then-catch-event/main.html index 7ed2719e7b..087affb1ad 100644 --- a/test/runtime/samples/await-then-catch-event/main.html +++ b/test/runtime/samples/await-then-catch-event/main.html @@ -7,7 +7,7 @@ {#await thePromise}

loading...

{:then theValue} - + {:catch theError}

oh no! {theError.message}

{/await} \ No newline at end of file diff --git a/test/runtime/samples/before-render-chain/main.html b/test/runtime/samples/before-render-chain/main.html index 8156f7e8a5..e194fe786a 100644 --- a/test/runtime/samples/before-render-chain/main.html +++ b/test/runtime/samples/before-render-chain/main.html @@ -4,4 +4,4 @@ import List from './List.html'; - + diff --git a/test/runtime/samples/binding-select-in-yield/main.html b/test/runtime/samples/binding-select-in-yield/main.html index 38304fba80..cb1499e1c7 100644 --- a/test/runtime/samples/binding-select-in-yield/main.html +++ b/test/runtime/samples/binding-select-in-yield/main.html @@ -6,7 +6,7 @@ export let letters = ['a', 'b', 'c']; - + {letter} + {:else} {component.name} {/if} diff --git a/test/runtime/samples/dynamic-component-ref/main.html b/test/runtime/samples/dynamic-component-ref/main.html index cd7b34ed54..fe9c52cab6 100644 --- a/test/runtime/samples/dynamic-component-ref/main.html +++ b/test/runtime/samples/dynamic-component-ref/main.html @@ -4,4 +4,4 @@ export let test; - + diff --git a/test/runtime/samples/event-handler-removal/main.html b/test/runtime/samples/event-handler-removal/main.html index 4589640ec6..29c7e32567 100644 --- a/test/runtime/samples/event-handler-removal/main.html +++ b/test/runtime/samples/event-handler-removal/main.html @@ -5,5 +5,5 @@ {#if visible} - + {/if} diff --git a/test/runtime/samples/immutable-nested/main.html b/test/runtime/samples/immutable-nested/main.html index f036cbdfc3..aa8efa9ebc 100644 --- a/test/runtime/samples/immutable-nested/main.html +++ b/test/runtime/samples/immutable-nested/main.html @@ -5,5 +5,5 @@
- +
diff --git a/test/runtime/samples/nested-transition-detach-if-false/main.html b/test/runtime/samples/nested-transition-detach-if-false/main.html index 41429fca38..d52c56c5cf 100644 --- a/test/runtime/samples/nested-transition-detach-if-false/main.html +++ b/test/runtime/samples/nested-transition-detach-if-false/main.html @@ -4,4 +4,4 @@ import Folder from './Folder.html'; - \ No newline at end of file + \ No newline at end of file diff --git a/test/runtime/samples/ondestroy-before-cleanup/Top.html b/test/runtime/samples/ondestroy-before-cleanup/Top.html index a0a3549ef4..273b89d836 100644 --- a/test/runtime/samples/ondestroy-before-cleanup/Top.html +++ b/test/runtime/samples/ondestroy-before-cleanup/Top.html @@ -9,4 +9,4 @@ }); -
+
diff --git a/test/runtime/samples/ondestroy-before-cleanup/main.html b/test/runtime/samples/ondestroy-before-cleanup/main.html index 15da7a5cba..34053dd613 100644 --- a/test/runtime/samples/ondestroy-before-cleanup/main.html +++ b/test/runtime/samples/ondestroy-before-cleanup/main.html @@ -6,5 +6,5 @@ {#if visible} - + {/if} \ No newline at end of file diff --git a/test/runtime/samples/onmount-fires-when-ready-nested/Widget.html b/test/runtime/samples/onmount-fires-when-ready-nested/Widget.html index 80c2dad6c5..a935dcf337 100644 --- a/test/runtime/samples/onmount-fires-when-ready-nested/Widget.html +++ b/test/runtime/samples/onmount-fires-when-ready-nested/Widget.html @@ -10,4 +10,4 @@ }); -

{inDocument}

+

{inDocument}

diff --git a/test/runtime/samples/onmount-fires-when-ready/Widget.html b/test/runtime/samples/onmount-fires-when-ready/Widget.html index 80c2dad6c5..a935dcf337 100644 --- a/test/runtime/samples/onmount-fires-when-ready/Widget.html +++ b/test/runtime/samples/onmount-fires-when-ready/Widget.html @@ -10,4 +10,4 @@ }); -

{inDocument}

+

{inDocument}

diff --git a/test/runtime/samples/refs-no-innerhtml/main.html b/test/runtime/samples/refs-no-innerhtml/main.html index e2f7740f2b..014fac9221 100644 --- a/test/runtime/samples/refs-no-innerhtml/main.html +++ b/test/runtime/samples/refs-no-innerhtml/main.html @@ -2,4 +2,4 @@ export let foo; -
+
diff --git a/test/runtime/samples/refs-unset/main.html b/test/runtime/samples/refs-unset/main.html index 6dc6d654da..9345408945 100644 --- a/test/runtime/samples/refs-unset/main.html +++ b/test/runtime/samples/refs-unset/main.html @@ -4,7 +4,7 @@ {#if x} - + {:else} - + {/if} diff --git a/test/runtime/samples/refs/main.html b/test/runtime/samples/refs/main.html index 68b013377d..9f71ec0a6b 100644 --- a/test/runtime/samples/refs/main.html +++ b/test/runtime/samples/refs/main.html @@ -2,4 +2,4 @@ export let foo; - + diff --git a/test/runtime/samples/transition-js-if-block-outro-timeout/main.html b/test/runtime/samples/transition-js-if-block-outro-timeout/main.html index 2e819c79ab..8b77998a94 100644 --- a/test/runtime/samples/transition-js-if-block-outro-timeout/main.html +++ b/test/runtime/samples/transition-js-if-block-outro-timeout/main.html @@ -13,5 +13,5 @@ {#if visible} -
yes
+
yes
{/if} \ No newline at end of file diff --git a/test/runtime/samples/transition-js-if-else-block-dynamic-outro/main.html b/test/runtime/samples/transition-js-if-else-block-dynamic-outro/main.html index 41809bd664..3fba1c9830 100644 --- a/test/runtime/samples/transition-js-if-else-block-dynamic-outro/main.html +++ b/test/runtime/samples/transition-js-if-else-block-dynamic-outro/main.html @@ -16,7 +16,7 @@ {#if x} -
{z}
+
{z}
{:else} -
{z}
+
{z}
{/if} \ No newline at end of file diff --git a/test/runtime/samples/transition-js-if-else-block-intro/main.html b/test/runtime/samples/transition-js-if-else-block-intro/main.html index 117f2ba8ee..d25cbb0412 100644 --- a/test/runtime/samples/transition-js-if-else-block-intro/main.html +++ b/test/runtime/samples/transition-js-if-else-block-intro/main.html @@ -15,7 +15,7 @@ {#if x} -
yes
+
yes
{:else} -
no
+
no
{/if} \ No newline at end of file diff --git a/test/runtime/samples/transition-js-if-else-block-outro/main.html b/test/runtime/samples/transition-js-if-else-block-outro/main.html index ba5c762146..c0c20e3c87 100644 --- a/test/runtime/samples/transition-js-if-else-block-outro/main.html +++ b/test/runtime/samples/transition-js-if-else-block-outro/main.html @@ -15,7 +15,7 @@ {#if x} -
yes
+
yes
{:else} -
no
+
no
{/if} \ No newline at end of file diff --git a/test/runtime/samples/transition-js-if-elseif-block-outro/main.html b/test/runtime/samples/transition-js-if-elseif-block-outro/main.html index ca4e4301da..462e073bd7 100644 --- a/test/runtime/samples/transition-js-if-elseif-block-outro/main.html +++ b/test/runtime/samples/transition-js-if-elseif-block-outro/main.html @@ -16,7 +16,7 @@ {#if x} -
yes
+
yes
{:elseif y} -
no
+
no
{/if} \ No newline at end of file diff --git a/test/server-side-rendering/samples/component-refs-and-attributes/main.html b/test/server-side-rendering/samples/component-refs-and-attributes/main.html index 86b3ddf1a9..8192bdf402 100644 --- a/test/server-side-rendering/samples/component-refs-and-attributes/main.html +++ b/test/server-side-rendering/samples/component-refs-and-attributes/main.html @@ -6,4 +6,4 @@ export let foo = 42; -
+
diff --git a/test/server-side-rendering/samples/component-refs/main.html b/test/server-side-rendering/samples/component-refs/main.html index 55d2abc4cd..96b3d15de4 100644 --- a/test/server-side-rendering/samples/component-refs/main.html +++ b/test/server-side-rendering/samples/component-refs/main.html @@ -4,4 +4,4 @@ import Widget from './Widget.html'; -
+
diff --git a/test/validator/samples/ref-not-supported-in-css/errors.json b/test/validator/samples/ref-not-supported-in-css/errors.json new file mode 100644 index 0000000000..3227c14cf7 --- /dev/null +++ b/test/validator/samples/ref-not-supported-in-css/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "invalid-ref-selector", + "message": "ref selectors are no longer supported", + "pos": 68, + "start": { + "line": 8, + "column": 1, + "character": 68 + }, + "end": { + "line": 8, + "column": 1, + "character": 68 + } +}] \ No newline at end of file diff --git a/test/validator/samples/ref-not-supported-in-css/input.html b/test/validator/samples/ref-not-supported-in-css/input.html new file mode 100644 index 0000000000..dcd6974ef1 --- /dev/null +++ b/test/validator/samples/ref-not-supported-in-css/input.html @@ -0,0 +1,11 @@ + + +
+ + \ No newline at end of file diff --git a/test/validator/samples/ref-not-supported/errors.json b/test/validator/samples/ref-not-supported/errors.json new file mode 100644 index 0000000000..43c8c07615 --- /dev/null +++ b/test/validator/samples/ref-not-supported/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "invalid-ref-directive", + "message": "The ref directive is no longer supported — use `bind:this={foo}` instead", + "pos": 5, + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 5, + "character": 5 + } +}] \ No newline at end of file diff --git a/test/validator/samples/ref-not-supported/input.html b/test/validator/samples/ref-not-supported/input.html new file mode 100644 index 0000000000..97e43ab90a --- /dev/null +++ b/test/validator/samples/ref-not-supported/input.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/validator/samples/reference-must-be-valid-name/errors.json b/test/validator/samples/reference-must-be-valid-name/errors.json deleted file mode 100644 index eb1c92d6d2..0000000000 --- a/test/validator/samples/reference-must-be-valid-name/errors.json +++ /dev/null @@ -1,15 +0,0 @@ -[{ - "message": "Reference name 'foo-bar' is invalid — must be a valid identifier such as foo_bar", - "start": { - "line": 1, - "column": 5, - "character": 5 - }, - "end": { - "line": 1, - "column": 16, - "character": 16 - }, - "pos": 5, - "code": "invalid-reference-name" -}] diff --git a/test/validator/samples/reference-must-be-valid-name/input.html b/test/validator/samples/reference-must-be-valid-name/input.html deleted file mode 100644 index a995bd8e6e..0000000000 --- a/test/validator/samples/reference-must-be-valid-name/input.html +++ /dev/null @@ -1,8 +0,0 @@ -
-
- -