Merge branch 'master' into api-reference

pull/2206/head
Richard Harris 7 years ago
commit 81e59157c2

8
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "svelte", "name": "svelte",
"version": "3.0.0-beta.15", "version": "3.0.0-beta.16",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -61,9 +61,9 @@
"dev": true "dev": true
}, },
"acorn": { "acorn": {
"version": "6.0.5", "version": "6.1.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.5.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz",
"integrity": "sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg==", "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==",
"dev": true "dev": true
}, },
"acorn-dynamic-import": { "acorn-dynamic-import": {

@ -1,6 +1,6 @@
{ {
"name": "svelte", "name": "svelte",
"version": "3.0.0-beta.15", "version": "3.0.0-beta.16",
"description": "The magical disappearing UI framework", "description": "The magical disappearing UI framework",
"module": "index.mjs", "module": "index.mjs",
"main": "index", "main": "index",
@ -51,7 +51,7 @@
"devDependencies": { "devDependencies": {
"@types/mocha": "^5.2.0", "@types/mocha": "^5.2.0",
"@types/node": "^10.5.5", "@types/node": "^10.5.5",
"acorn": "^6.0.5", "acorn": "^6.1.1",
"acorn-dynamic-import": "^4.0.0", "acorn-dynamic-import": "^4.0.0",
"agadoo": "^1.0.1", "agadoo": "^1.0.1",
"c8": "^3.4.0", "c8": "^3.4.0",

@ -76,7 +76,7 @@
window.location.hash = ''; window.location.hash = '';
window._svelteTransitionManager = null; window._svelteTransitionManager = null;
window.component = new SvelteComponent({ window.component = new SvelteComponent.default({
target: document.body target: document.body
}); });
`); `);

@ -14,7 +14,7 @@ self.addEventListener('message', async event => {
version === 'local' ? version === 'local' ?
'/repl/local?file=compiler.js' : '/repl/local?file=compiler.js' :
`https://unpkg.com/svelte@${version}/compiler.js`, `https://unpkg.com/svelte@${version}/compiler.js`,
`https://unpkg.com/rollup@0.68/dist/rollup.browser.js` `https://unpkg.com/rollup@1/dist/rollup.browser.js`
); );
fulfil(); fulfil();
@ -62,7 +62,6 @@ function fetch_if_uncached(url) {
async function getBundle(mode, cache, lookup) { async function getBundle(mode, cache, lookup) {
let bundle; let bundle;
let error;
const all_warnings = []; const all_warnings = [];
const new_cache = {}; const new_cache = {};
@ -89,6 +88,8 @@ async function getBundle(mode, cache, lookup) {
if (importee.endsWith('.html')) importee = importee.replace(/\.html$/, '.svelte'); if (importee.endsWith('.html')) importee = importee.replace(/\.html$/, '.svelte');
if (importee in lookup) return importee; if (importee in lookup) return importee;
throw new Error(`Could not resolve "${importee}" from "${importer}"`);
}, },
load(id) { load(id) {
if (id.startsWith(`https://`)) return fetch_if_uncached(id); if (id.startsWith(`https://`)) return fetch_if_uncached(id);
@ -104,7 +105,7 @@ async function getBundle(mode, cache, lookup) {
: svelte.compile(code, Object.assign({ : svelte.compile(code, Object.assign({
generate: mode, generate: mode,
format: 'esm', format: 'esm',
name: name, name,
filename: name + '.svelte' filename: name + '.svelte'
}, commonCompilerOptions)); }, commonCompilerOptions));
@ -122,6 +123,7 @@ async function getBundle(mode, cache, lookup) {
return result.js; return result.js;
} }
}], }],
inlineDynamicImports: true,
onwarn(warning) { onwarn(warning) {
all_warnings.push({ all_warnings.push({
message: warning.message message: warning.message
@ -129,7 +131,7 @@ async function getBundle(mode, cache, lookup) {
} }
}); });
} catch (error) { } catch (error) {
return { error, bundle: null, cache: new_cache, warnings: all_warnings } return { error, bundle: null, cache: new_cache, warnings: all_warnings };
} }
return { bundle, cache: new_cache, error: null, warnings: all_warnings }; return { bundle, cache: new_cache, error: null, warnings: all_warnings };
@ -166,7 +168,7 @@ async function bundle(components) {
let uid = 1; let uid = 1;
const dom_result = await dom.bundle.generate({ const dom_result = (await dom.bundle.generate({
format: 'iife', format: 'iife',
name: 'SvelteComponent', name: 'SvelteComponent',
globals: id => { globals: id => {
@ -174,8 +176,9 @@ async function bundle(components) {
import_map.set(id, name); import_map.set(id, name);
return name; return name;
}, },
exports: 'named',
sourcemap: true sourcemap: true
}); })).output[0];
if (token !== currentToken) return; if (token !== currentToken) return;
@ -193,16 +196,17 @@ async function bundle(components) {
if (token !== currentToken) return; if (token !== currentToken) return;
const ssr_result = ssr const ssr_result = ssr
? await ssr.bundle.generate({ ? (await ssr.bundle.generate({
format: 'iife', format: 'iife',
name: 'SvelteComponent', name: 'SvelteComponent',
globals: id => import_map.get(id), globals: id => import_map.get(id),
exports: 'named',
sourcemap: true sourcemap: true
}) })).output[0]
: null; : null;
return { return {
imports: dom.bundle.imports, imports: dom_result.imports,
import_map, import_map,
dom: dom_result, dom: dom_result,
ssr: ssr_result, ssr: ssr_result,

@ -438,6 +438,12 @@ export default class Component {
} }
if (node.type === 'ExportNamedDeclaration') { if (node.type === 'ExportNamedDeclaration') {
if (node.source) {
this.error(node, {
code: `not-implemented`,
message: `A component currently cannot have an export ... from`
});
}
if (node.declaration) { if (node.declaration) {
if (node.declaration.type === 'VariableDeclaration') { if (node.declaration.type === 'VariableDeclaration') {
node.declaration.declarations.forEach(declarator => { node.declaration.declarations.forEach(declarator => {
@ -1034,7 +1040,10 @@ export default class Component {
if (!assignee_nodes.has(identifier)) { if (!assignee_nodes.has(identifier)) {
const { name } = identifier; const { name } = identifier;
const owner = scope.findOwner(name); const owner = scope.findOwner(name);
if ((!owner || owner === component.instance_scope) && (name[0] === '$' || component.var_lookup.has(name))) { if (
(!owner || owner === component.instance_scope) &&
(name[0] === '$' || component.var_lookup.has(name) && component.var_lookup.get(name).writable)
) {
dependencies.add(name); dependencies.add(name);
} }
} }

@ -239,6 +239,8 @@ export default class Block {
const properties = new CodeBuilder(); const properties = new CodeBuilder();
const methodName = (short: string, long: string) => dev ? `${short}: function ${this.getUniqueName(long)}` : short;
if (localKey) { if (localKey) {
properties.addBlock(`key: ${localKey},`); properties.addBlock(`key: ${localKey},`);
} }
@ -258,7 +260,7 @@ export default class Block {
); );
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'c: function create' : 'c'}() { ${methodName('c', 'create')}() {
${this.builders.create} ${this.builders.create}
${hydrate} ${hydrate}
}, },
@ -270,7 +272,7 @@ export default class Block {
properties.addLine(`l: @noop,`); properties.addLine(`l: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'l: function claim' : 'l'}(nodes) { ${methodName('l', 'claim')}(nodes) {
${this.builders.claim} ${this.builders.claim}
${this.renderer.options.hydratable && !this.builders.hydrate.isEmpty() && `this.h();`} ${this.renderer.options.hydratable && !this.builders.hydrate.isEmpty() && `this.h();`}
}, },
@ -280,7 +282,7 @@ export default class Block {
if (this.renderer.options.hydratable && !this.builders.hydrate.isEmpty()) { if (this.renderer.options.hydratable && !this.builders.hydrate.isEmpty()) {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'h: function hydrate' : 'h'}() { ${methodName('h', 'hydrate')}() {
${this.builders.hydrate} ${this.builders.hydrate}
}, },
`); `);
@ -290,7 +292,7 @@ export default class Block {
properties.addLine(`m: @noop,`); properties.addLine(`m: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'm: function mount' : 'm'}(#target, anchor) { ${methodName('m', 'mount')}(#target, anchor) {
${this.builders.mount} ${this.builders.mount}
}, },
`); `);
@ -301,7 +303,7 @@ export default class Block {
properties.addLine(`p: @noop,`); properties.addLine(`p: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'p: function update' : 'p'}(changed, ${this.maintainContext ? 'new_ctx' : 'ctx'}) { ${methodName('p', 'update')}(changed, ${this.maintainContext ? 'new_ctx' : 'ctx'}) {
${this.maintainContext && `ctx = new_ctx;`} ${this.maintainContext && `ctx = new_ctx;`}
${this.builders.update} ${this.builders.update}
}, },
@ -311,15 +313,15 @@ export default class Block {
if (this.hasAnimation) { if (this.hasAnimation) {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? `r: function measure` : `r`}() { ${methodName('r', 'measure')}() {
${this.builders.measure} ${this.builders.measure}
}, },
${dev ? `f: function fix` : `f`}() { ${methodName('f', 'fix')}() {
${this.builders.fix} ${this.builders.fix}
}, },
${dev ? `a: function animate` : `a`}() { ${methodName('a', 'animate')}() {
${this.builders.animate} ${this.builders.animate}
}, },
`); `);
@ -330,7 +332,7 @@ export default class Block {
properties.addLine(`i: @noop,`); properties.addLine(`i: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#local) { ${methodName('i', 'intro')}(#local) {
${this.hasOutros && `if (#current) return;`} ${this.hasOutros && `if (#current) return;`}
${this.builders.intro} ${this.builders.intro}
}, },
@ -341,7 +343,7 @@ export default class Block {
properties.addLine(`o: @noop,`); properties.addLine(`o: @noop,`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}(#local) { ${methodName('o', 'outro')}(#local) {
${this.builders.outro} ${this.builders.outro}
}, },
`); `);
@ -352,7 +354,7 @@ export default class Block {
properties.addLine(`d: @noop`); properties.addLine(`d: @noop`);
} else { } else {
properties.addBlock(deindent` properties.addBlock(deindent`
${dev ? 'd: function destroy' : 'd'}(detach) { ${methodName('d', 'destroy')}(detach) {
${this.builders.destroy} ${this.builders.destroy}
} }
`); `);

@ -17,11 +17,11 @@ let a = 1;
let b = 2; let b = 2;
function instance($$self, $$props, $$invalidate) { function instance($$self, $$props, $$invalidate) {
let max; let max;
$$self.$$.update = ($$dirty = { Math: 1, a: 1, b: 1 }) => { $$self.$$.update = ($$dirty = { a: 1, b: 1 }) => {
if ($$dirty.a || $$dirty.b) { if ($$dirty.a || $$dirty.b) {
max = Math.max(a, b); $$invalidate('max', max); max = Math.max(a, b); $$invalidate('max', max);
} }

@ -0,0 +1,7 @@
[{
"message": "Invalid reactive declaration — must depend on local state",
"code": "invalid-reactive-declaration",
"start": { "line": 2, "column": 1, "character": 10 },
"end": { "line": 2, "column": 23, "character": 32 },
"pos": 10
}]

@ -0,0 +1,3 @@
<script>
$: console.log('foo');
</script>
Loading…
Cancel
Save