diff --git a/.gitignore b/.gitignore index 3a7d2ce532..a78b294346 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ node_modules *.map /src/compile/internal-exports.ts -/cli/ /compiler.js /index.js /internal.* @@ -14,7 +13,6 @@ node_modules /scratch/ /coverage/ /coverage.lcov/ -/test/cli/samples/*/actual /test/sourcemaps/samples/*/output.js /test/sourcemaps/samples/*/output.js.map /test/sourcemaps/samples/*/output.css diff --git a/package-lock.json b/package-lock.json index 7862b8b66d..e1b29982dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "3.0.0-beta.8", + "version": "3.0.0-beta.10", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1950,12 +1950,6 @@ } } }, - "interpret": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz", - "integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==", - "dev": true - }, "invert-kv": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", @@ -2697,12 +2691,6 @@ } } }, - "mri": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/mri/-/mri-1.1.4.tgz", - "integrity": "sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w==", - "dev": true - }, "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", @@ -2831,33 +2819,6 @@ "integrity": "sha1-jZ2+KJZKSsVxLpExZCEHxx6Q7EA=", "dev": true }, - "node-resolve": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/node-resolve/-/node-resolve-1.3.4.tgz", - "integrity": "sha512-yQ8Qn3GGR4cyunvggEHg7fb37V/6atft1K/xU6b2OEfJDbi8zbRSNIKxClzJszAV6tjtYyZt1vHlBgdORMcPXg==", - "dev": true, - "requires": { - "is-builtin-module": "^3.0.0", - "lodash": "^4.13.1" - }, - "dependencies": { - "builtin-modules": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.0.0.tgz", - "integrity": "sha512-hMIeU4K2ilbXV6Uv93ZZ0Avg/M91RaKXucQ+4me2Do1txxBDyDZWCBa5bJSLqoNTRpXTLwEzIk1KmloenDDjhg==", - "dev": true - }, - "is-builtin-module": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.0.0.tgz", - "integrity": "sha512-/93sDihsAD652hrMEbJGbMAVBf1qc96kyThHQ0CAOONHaE3aROLpTjDe4WQ5aoC5ITHFxEq1z8XqSU7km+8amw==", - "dev": true, - "requires": { - "builtin-modules": "^3.0.0" - } - } - } - }, "normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -3374,15 +3335,6 @@ "util-deprecate": "^1.0.1" } }, - "rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", - "dev": true, - "requires": { - "resolve": "^1.1.6" - } - }, "redent": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-1.0.0.tgz", @@ -3951,15 +3903,6 @@ "tslib": "^1.9.0" } }, - "sade": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/sade/-/sade-1.4.2.tgz", - "integrity": "sha512-MTrQm+Nhl4m1mbssYDgAculC/HbShjj08QtHnA2GTpzivfU5aUp8EoHlECmrIHEaa8hZRZSp2Gygv8VMlpXEBw==", - "dev": true, - "requires": { - "mri": "^1.1.0" - } - }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -3981,17 +3924,6 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, - "sander": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/sander/-/sander-0.6.0.tgz", - "integrity": "sha1-rxYkzX+2362Y6+9WUxn5IAeNqSU=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.3", - "mkdirp": "^0.5.1", - "rimraf": "^2.5.2" - } - }, "saxes": { "version": "3.1.6", "resolved": "https://registry.npmjs.org/saxes/-/saxes-3.1.6.tgz", @@ -4051,17 +3983,6 @@ "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, - "shelljs": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.3.tgz", - "integrity": "sha512-fc0BKlAWiLpwZljmOvAOTE/gXawtCoNrP5oaY7KIaQbbyHeQVg01pSEuEGvGh3HEdBU4baCD7wQBwADmM/7f7A==", - "dev": true, - "requires": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - } - }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", diff --git a/package.json b/package.json index dcf07d8025..cf021b6045 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,10 @@ { "name": "svelte", - "version": "3.0.0-beta.8", + "version": "3.0.0-beta.10", "description": "The magical disappearing UI framework", "module": "index.mjs", "main": "index", - "bin": { - "svelte": "svelte" - }, "files": [ - "cli", "compiler.js", "register.js", "index.*", @@ -72,7 +68,6 @@ "magic-string": "^0.25.2", "mocha": "^5.2.0", "nightmare": "^3.0.1", - "node-resolve": "^1.3.3", "rollup": "^1.1.2", "rollup-plugin-commonjs": "^9.1.0", "rollup-plugin-json": "^3.0.0", @@ -81,9 +76,6 @@ "rollup-plugin-sucrase": "^2.1.0", "rollup-plugin-typescript": "^1.0.0", "rollup-plugin-virtual": "^1.0.1", - "sade": "^1.4.0", - "sander": "^0.6.0", - "shelljs": "^0.8.2", "source-map": "0.6", "source-map-support": "^0.5.4", "tiny-glob": "^0.2.1", diff --git a/rollup.config.js b/rollup.config.js index ad58d25f22..c523cb004d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -69,27 +69,6 @@ export default [ : id => id === 'acorn' || id === 'magic-string' || id.startsWith('css-tree') }, - /* cli/*.js */ - { - input: ['src/cli/index.ts'], - output: { - dir: 'cli', - format: 'cjs', - paths: { - svelte: '../compiler.js' - } - }, - external: ['fs', 'path', 'os', 'svelte'], - plugins: [ - json(), - commonjs(), - resolve(), - typescript({ - typescript: require('typescript') - }) - ] - }, - /* motion.mjs */ { input: `src/motion/index.js`, diff --git a/site/package.json b/site/package.json index 605682db32..fe3cf9e65f 100644 --- a/site/package.json +++ b/site/package.json @@ -53,6 +53,10 @@ "rollup-plugin-svelte": "^5.0.3", "rollup-plugin-terser": "^4.0.4", "sapper": "^0.26.0-alpha.10", +<<<<<<< HEAD "svelte": "^3.0.0-beta.10" +======= + "svelte": "^3.0.0-beta.8" +>>>>>>> master } } diff --git a/src/cli/compile.ts b/src/cli/compile.ts deleted file mode 100644 index f8928c29cf..0000000000 --- a/src/cli/compile.ts +++ /dev/null @@ -1,131 +0,0 @@ -import * as path from 'path'; -import * as fs from 'fs'; -import * as svelte from 'svelte'; -import error from './error.js'; - -function mkdirp(dir) { - const parent = path.dirname(dir); - if (dir === parent) return; - - mkdirp(parent); - if (!fs.existsSync(dir)) fs.mkdirSync(dir); -} - -export function compile(input, opts) { - if (opts._.length > 0) { - error(`Can only compile a single file or directory`); - } - - const output = opts.output; - - const stats = fs.statSync(input); - const isDir = stats.isDirectory(); - - if (isDir) { - if (!output) { - error(`You must specify an --output (-o) option when compiling a directory of files`); - } - - if (opts.name || opts.amdId) { - error(`Cannot specify --${opts.name ? 'name' : 'amdId'} when compiling a directory`); - } - } - - const options = { - name: opts.name, - format: opts.format, - css: opts.css !== false, - dev: opts.dev, - immutable: opts.immutable, - generate: opts.generate || 'dom', - customElement: opts.customElement, - sveltePath: opts.sveltePath - }; - - if (isDir) { - mkdirp(output); - compileDirectory(input, output, options, opts.sourcemap); - } else { - compileFile(input, output, options, opts.sourcemap); - } -} - -function compileDirectory(input, output, options, sourcemap) { - fs.readdirSync(input).forEach(file => { - const src = path.resolve(input, file); - const dest = path.resolve(output, file); - - if (path.extname(file) === '.html') { - compileFile( - src, - dest.substring(0, dest.lastIndexOf('.html')) + '.js', - options, - sourcemap - ); - } else { - const stats = fs.statSync(src); - if (stats.isDirectory()) { - compileDirectory(src, dest, options, sourcemap); - } - } - }); -} - -let SOURCEMAPPING_URL = 'sourceMa'; -SOURCEMAPPING_URL += 'ppingURL'; - -function compileFile(input, output, options, sourcemap) { - console.error(`compiling ${path.relative(process.cwd(), input)}...`); // eslint-disable-line no-console - - options = Object.assign({}, options); - if (!options.name) options.name = getName(input); - - options.filename = input; - options.outputFilename = output; - - const inline = sourcemap === 'inline'; - - let source = fs.readFileSync(input, 'utf-8'); - if (source[0] === 0xfeff) source = source.slice(1); - - let compiled; - - try { - compiled = svelte.compile(source, options); - } catch (err) { - error(err); - } - - const { js, warnings } = compiled; - - warnings.forEach(warning => console.warn(warning.toString())); - - if (sourcemap) { - js.code += `\n//# ${SOURCEMAPPING_URL}=${inline || !output - ? js.map.toUrl() - : `${path.basename(output)}.map`}\n`; - } - - if (output) { - const outputDir = path.dirname(output); - mkdirp(outputDir); - fs.writeFileSync(output, js.code); - console.error(`wrote ${path.relative(process.cwd(), output)}`); // eslint-disable-line no-console - if (sourcemap && !inline) { - fs.writeFileSync(`${output}.map`, js.map); - console.error(`wrote ${path.relative(process.cwd(), `${output}.map`)}`); // eslint-disable-line no-console - } - } else { - process.stdout.write(js.code); - } -} - -function getName(input) { - return path - .basename(input) - .replace(path.extname(input), '') - .replace(/[^a-zA-Z_$0-9]+/g, '_') - .replace(/^_/, '') - .replace(/_$/, '') - .replace(/^(\d)/, '_$1'); -} diff --git a/src/cli/error.ts b/src/cli/error.ts deleted file mode 100644 index 2413ab9ee5..0000000000 --- a/src/cli/error.ts +++ /dev/null @@ -1,17 +0,0 @@ -import c from 'kleur'; - -function stderr(msg) { - console.error(msg); // eslint-disable-line no-console -} - -export default function error(err) { - stderr(c.red(err.message || err)); - - if (err.frame) { - stderr(err.frame); - } else if (err.stack) { - stderr(c.gray(err.stack)); - } - - process.exit(1); -} diff --git a/src/cli/index.ts b/src/cli/index.ts deleted file mode 100644 index 309d23acda..0000000000 --- a/src/cli/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -import sade from 'sade'; -import * as pkg from '../../package.json'; - -const prog = sade('svelte').version(pkg.version); - -prog - .command('compile ') - - .option('-o, --output', 'Output (if absent, prints to stdout)') - .option('-f, --format', 'Type of output (cjs or esm)', 'esm') - .option('-n, --name', 'Name for IIFE/UMD export (inferred from filename by default)') - .option('-m, --sourcemap', 'Generate sourcemap (`-m inline` for inline map)') - .option('-d, --dev', 'Add dev mode warnings and errors') - .option('--generate', 'Change generate format between `dom` and `ssr`') - .option('--no-css', `Don't include CSS (useful with SSR)`) - .option('--immutable', 'Support immutable data structures') - .option('--shared', 'Don\'t include shared helpers') - .option('--customElement', 'Generate a custom element') - - .example('compile App.html > App.js') - .example('compile src -o dest') - .example('compile -f umd MyComponent.html > MyComponent.js') - - .action((input, opts) => { - import('./compile').then(({ compile }) => { - compile(input, opts); - }); - }) - - .parse(process.argv); \ No newline at end of file diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 32af20c12c..1b843e9ca2 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -826,6 +826,7 @@ export default class Component { declarators: [declarator], insert: get_insert(variable) }); + current_group = null; } else { if (current_group && current_group.kind !== node.kind) { current_group = null; diff --git a/src/compile/nodes/Action.ts b/src/compile/nodes/Action.ts index 80d8f215c5..761738ac79 100644 --- a/src/compile/nodes/Action.ts +++ b/src/compile/nodes/Action.ts @@ -14,6 +14,7 @@ export default class Action extends Node { component.warn_if_undefined(info, scope); this.name = info.name; + component.qualify(info.name); this.expression = info.expression ? new Expression(component, this, scope, info.expression) diff --git a/src/compile/nodes/Animation.ts b/src/compile/nodes/Animation.ts index faf964b06c..68ebfd3828 100644 --- a/src/compile/nodes/Animation.ts +++ b/src/compile/nodes/Animation.ts @@ -13,6 +13,7 @@ export default class Animation extends Node { component.warn_if_undefined(info, scope); this.name = info.name; + component.qualify(info.name); if (parent.animation) { component.error(this, { diff --git a/src/compile/nodes/EventHandler.ts b/src/compile/nodes/EventHandler.ts index e426efa79c..ee9db7a850 100644 --- a/src/compile/nodes/EventHandler.ts +++ b/src/compile/nodes/EventHandler.ts @@ -32,7 +32,7 @@ export default class EventHandler extends Node { if (node && node.type === 'VariableDeclaration') { // for `const handleClick = () => {...}`, we want the [arrow] function expression node const declarator = node.declarations.find(d => d.id.name === info.expression.name); - node = declarator.init; + node = declarator && declarator.init; } if (node && /Function/.test(node.type) && node.params.length === 0) { diff --git a/src/compile/nodes/Transition.ts b/src/compile/nodes/Transition.ts index a0e42d939e..6cb39b997f 100644 --- a/src/compile/nodes/Transition.ts +++ b/src/compile/nodes/Transition.ts @@ -15,6 +15,8 @@ export default class Transition extends Node { component.warn_if_undefined(info, scope); this.name = info.name; + component.qualify(info.name); + this.directive = info.intro && info.outro ? 'transition' : info.intro ? 'in' : 'out'; this.is_local = info.modifiers.includes('local'); diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 7a3b714d5c..980ec8555a 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -86,58 +86,73 @@ export default function mustache(parser: Parser) { block.end = parser.index; parser.stack.pop(); - } else if (parser.eat(':elseif')) { - const block = parser.current(); - if (block.type !== 'IfBlock') + } else if (parser.eat(':else')) { + if (parser.eat('if')) { parser.error({ - code: `invalid-elseif-placement`, - message: 'Cannot have an {:elseif ...} block outside an {#if ...} block' + code: 'invalid-elseif', + message: `'elseif' should be 'else if'` }); + } - parser.requireWhitespace(); + parser.allowWhitespace(); - const expression = readExpression(parser); + // :else if + if (parser.eat('if')) { + const block = parser.current(); + if (block.type !== 'IfBlock') + parser.error({ + code: `invalid-elseif-placement`, + message: 'Cannot have an {:else if ...} block outside an {#if ...} block' + }); - parser.allowWhitespace(); - parser.eat('}', true); + parser.requireWhitespace(); - block.else = { - start: parser.index, - end: null, - type: 'ElseBlock', - children: [ - { - start: parser.index, - end: null, - type: 'IfBlock', - elseif: true, - expression, - children: [], - }, - ], - }; + const expression = readExpression(parser); - parser.stack.push(block.else.children[0]); - } else if (parser.eat(':else')) { - const block = parser.current(); - if (block.type !== 'IfBlock' && block.type !== 'EachBlock') { - parser.error({ - code: `invalid-else-placement`, - message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block' - }); + parser.allowWhitespace(); + parser.eat('}', true); + + block.else = { + start: parser.index, + end: null, + type: 'ElseBlock', + children: [ + { + start: parser.index, + end: null, + type: 'IfBlock', + elseif: true, + expression, + children: [], + }, + ], + }; + + parser.stack.push(block.else.children[0]); } - parser.allowWhitespace(); - parser.eat('}', true); + // :else + else { + const block = parser.current(); + if (block.type !== 'IfBlock' && block.type !== 'EachBlock') { + parser.error({ + code: `invalid-else-placement`, + message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block' + }); + } + + parser.allowWhitespace(); + parser.eat('}', true); - block.else = { - start: parser.index, - end: null, - type: 'ElseBlock', - children: [], - }; + block.else = { + start: parser.index, + end: null, + type: 'ElseBlock', + children: [], + }; - parser.stack.push(block.else); + parser.stack.push(block.else); + } } else if (parser.eat(':then')) { // TODO DRY out this and the next section const pendingBlock = parser.current(); diff --git a/store.mjs b/store.mjs index 5f005f15d5..ba1b89a5c3 100644 --- a/store.mjs +++ b/store.mjs @@ -1,4 +1,4 @@ -import { run_all, noop } from './internal'; +import { run_all, noop, get_store_value } from './internal'; export function readable(start, value) { const subscribers = []; @@ -103,3 +103,5 @@ export function derive(stores, fn) { }; }); } + +export { get_store_value as get }; diff --git a/test/cli/index.js b/test/cli/index.js deleted file mode 100644 index f1779b1ea1..0000000000 --- a/test/cli/index.js +++ /dev/null @@ -1,84 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const assert = require('assert'); -const glob = require('tiny-glob/sync.js'); -const shell = require("shelljs"); - -const cli = path.resolve(__dirname, "../../cli/index.js"); - -function normalize(str) { - return str - .replace(/^\s+$/gm, '') - .replace( - /\/\*(.*?)generated by Svelte v[.\d]+/, - (_, path) => `/*${path.replace(/\\/g, '/')}generated by Svelte vx.y.z` - ) - .trim(); -} - -const cwd = process.cwd(); - -// TODO figure out what to do with the CLI -describe.skip('cli', function() { - this.timeout(10000); - - afterEach(() => { - process.chdir(cwd); - }); - - fs.readdirSync('test/cli/samples').forEach(dir => { - if (dir[0] === '.') return; - - // append .solo to test dir to only run that test - const solo = /\.solo$/.test(dir); - - (solo ? it.only : it)(dir, done => { - process.chdir(`${__dirname}/samples/${dir}`); - - const command = fs.readFileSync('command.sh', 'utf-8'); - - shell.mkdir("-p", "actual"); - shell.rm("-rf", "actual/*"); - const { commandErr } = shell.exec( - command.replace(/^svelte /, `node ${cli} `) - ); - - if (commandErr) { - done(commandErr); - return; - } - - const actual = glob('**', { cwd: 'actual', filesOnly: true }) - .map(file => { - return { - file, - contents: normalize(fs.readFileSync(`actual/${file}`, 'utf-8')) - }; - }); - - const expected = glob('**', { cwd: 'expected', filesOnly: true }) - .map(file => { - return { - file, - contents: normalize( - fs.readFileSync(`expected/${file}`, 'utf-8') - ) - }; - }); - - actual.forEach((a, i) => { - const e = expected[i]; - - assert.equal(a.file, e.file, 'File list mismatch'); - - if (/\.map$/.test(a.file)) { - assert.deepEqual(JSON.parse(a.contents), JSON.parse(e.contents)); - } else { - assert.equal(a.contents, e.contents); - } - }); - - done(); - }); - }); -}); diff --git a/test/cli/samples/basic/command.sh b/test/cli/samples/basic/command.sh deleted file mode 100644 index 9e272a7d5b..0000000000 --- a/test/cli/samples/basic/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src/Main.svelte > actual/Main.js diff --git a/test/cli/samples/basic/expected/Main.js b/test/cli/samples/basic/expected/Main.js deleted file mode 100644 index ecc2beb83c..0000000000 --- a/test/cli/samples/basic/expected/Main.js +++ /dev/null @@ -1,191 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var p; - - return { - c() { - p = createElement("p"); - p.textContent = "Hello world!"; - }, - - m(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -function Main(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function noop() {} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; \ No newline at end of file diff --git a/test/cli/samples/basic/src/Main.svelte b/test/cli/samples/basic/src/Main.svelte deleted file mode 100644 index aa994ea13e..0000000000 --- a/test/cli/samples/basic/src/Main.svelte +++ /dev/null @@ -1 +0,0 @@ -

Hello world!

\ No newline at end of file diff --git a/test/cli/samples/custom-element/command.sh b/test/cli/samples/custom-element/command.sh deleted file mode 100644 index ee9f854e9b..0000000000 --- a/test/cli/samples/custom-element/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src/Main.svelte --customElement > actual/Main.js diff --git a/test/cli/samples/custom-element/expected/Main.js b/test/cli/samples/custom-element/expected/Main.js deleted file mode 100644 index f6befc4e3b..0000000000 --- a/test/cli/samples/custom-element/expected/Main.js +++ /dev/null @@ -1,212 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var p; - - return { - c() { - p = createElement("p"); - p.textContent = "Hello world!"; - this.c = noop; - }, - - m(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -class Main extends HTMLElement { - constructor(options = {}) { - super(); - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this.attachShadow({ mode: 'open' }); - - this._fragment = create_main_fragment(this, this._state); - - this._fragment.c(); - this._fragment.m(this.shadowRoot, null); - - if (options.target) this._mount(options.target, options.anchor); - } - - static get observedAttributes() { - return []; - } - - attributeChangedCallback(attr, oldValue, newValue) { - this.set({ [attr]: newValue }); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); -assign(Main.prototype, { - _mount(target, anchor) { - target.insertBefore(this, anchor); - } -}); - -customElements.define("my-element", Main); - -Main.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function noop() {} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; \ No newline at end of file diff --git a/test/cli/samples/custom-element/src/Main.svelte b/test/cli/samples/custom-element/src/Main.svelte deleted file mode 100644 index 6323e9e8d1..0000000000 --- a/test/cli/samples/custom-element/src/Main.svelte +++ /dev/null @@ -1,3 +0,0 @@ - - -

Hello world!

diff --git a/test/cli/samples/dev/command.sh b/test/cli/samples/dev/command.sh deleted file mode 100644 index b9dc99e7d1..0000000000 --- a/test/cli/samples/dev/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src/Main.svelte -d > actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/dev/expected/Main.js b/test/cli/samples/dev/expected/Main.js deleted file mode 100644 index db75c4a5c1..0000000000 --- a/test/cli/samples/dev/expected/Main.js +++ /dev/null @@ -1,227 +0,0 @@ -/* src/Main.svelte generated by Svelte v2.13.4 */ - -const file = "src/Main.svelte"; - -function create_main_fragment(component, ctx) { - var p; - - return { - c: function create() { - p = createElement("p"); - p.textContent = "Hello world!"; - addLoc(p, file, 0, 0, 0); - }, - - m: function mount(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d: function destroy(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -function Main(options) { - this._debugName = '
'; - if (!options || (!options.target && !options.root)) { - throw new Error("'target' is a required option"); - } - - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Main.prototype, { - destroy: destroyDev, - get: get, - fire: fire, - on: on, - set: setDev, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._checkReadOnly = function _checkReadOnly(newState) { -}; - -Main.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function addLoc(element, file, line, column, char) { - element.__svelte_meta = { - loc: { file, line, column, char } - }; -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function noop() {} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroyDev(detach) { - destroy.call(this, detach); - this.destroy = function() { - console.warn('Component was already destroyed'); - }; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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 setDev(newState) { - if (typeof newState !== 'object') { - throw new Error( - this._debugName + '.set was called without an object of data key-values to update.' - ); - } - - this._checkReadOnly(newState); - set.call(this, newState); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function set(newState) { - this._set(assign({}, newState)); - if (this.root._lock) return; - flush(this.root); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; \ No newline at end of file diff --git a/test/cli/samples/dev/src/Main.svelte b/test/cli/samples/dev/src/Main.svelte deleted file mode 100644 index aa994ea13e..0000000000 --- a/test/cli/samples/dev/src/Main.svelte +++ /dev/null @@ -1 +0,0 @@ -

Hello world!

\ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/command.sh b/test/cli/samples/dir-sourcemap/command.sh deleted file mode 100644 index 37089f3f44..0000000000 --- a/test/cli/samples/dir-sourcemap/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src -m -o actual \ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/expected/Main.js b/test/cli/samples/dir-sourcemap/expected/Main.js deleted file mode 100644 index e164569e1c..0000000000 --- a/test/cli/samples/dir-sourcemap/expected/Main.js +++ /dev/null @@ -1,186 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ -import Widget from './Widget.svelte'; - - - -function create_main_fragment(component, ctx) { - - var widget = new Widget({ - root: component.root, - store: component.store - }); - - return { - c() { - widget._fragment.c(); - }, - - m(target, anchor) { - widget._mount(target, anchor); - }, - - p: noop, - - d(detach) { - widget.destroy(detach); - } - }; -} - -function Main(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - - flush(this); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._recompute = noop; - -function noop() {} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; -//# sourceMappingURL=Main.js.map diff --git a/test/cli/samples/dir-sourcemap/expected/Main.js.map b/test/cli/samples/dir-sourcemap/expected/Main.js.map deleted file mode 100644 index a0f4cf48c7..0000000000 --- a/test/cli/samples/dir-sourcemap/expected/Main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Main.js","sources":["../src/Main.svelte"],"sourcesContent":["\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/expected/Widget.js b/test/cli/samples/dir-sourcemap/expected/Widget.js deleted file mode 100644 index d55dcbda4c..0000000000 --- a/test/cli/samples/dir-sourcemap/expected/Widget.js +++ /dev/null @@ -1,192 +0,0 @@ -/* src/Widget.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var p; - - return { - c() { - p = createElement("p"); - p.textContent = "widget"; - }, - - m(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -function Widget(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Widget.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Widget.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function noop() {} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Widget; -//# sourceMappingURL=Widget.js.map diff --git a/test/cli/samples/dir-sourcemap/expected/Widget.js.map b/test/cli/samples/dir-sourcemap/expected/Widget.js.map deleted file mode 100644 index 37247333ed..0000000000 --- a/test/cli/samples/dir-sourcemap/expected/Widget.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Widget.js","sources":["../src/Widget.svelte"],"sourcesContent":["

widget

"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/src/Main.svelte b/test/cli/samples/dir-sourcemap/src/Main.svelte deleted file mode 100644 index 0a9d5bba87..0000000000 --- a/test/cli/samples/dir-sourcemap/src/Main.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - - \ No newline at end of file diff --git a/test/cli/samples/dir-sourcemap/src/Widget.svelte b/test/cli/samples/dir-sourcemap/src/Widget.svelte deleted file mode 100644 index 963b8f1a2a..0000000000 --- a/test/cli/samples/dir-sourcemap/src/Widget.svelte +++ /dev/null @@ -1 +0,0 @@ -

widget

\ No newline at end of file diff --git a/test/cli/samples/dir-subdir/command.sh b/test/cli/samples/dir-subdir/command.sh deleted file mode 100644 index 10067cb1f9..0000000000 --- a/test/cli/samples/dir-subdir/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src -o actual \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/expected/Main.js b/test/cli/samples/dir-subdir/expected/Main.js deleted file mode 100644 index 3026a122e2..0000000000 --- a/test/cli/samples/dir-subdir/expected/Main.js +++ /dev/null @@ -1,185 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ -import Widget from './widget/Widget.svelte'; - - - -function create_main_fragment(component, ctx) { - - var widget = new Widget({ - root: component.root, - store: component.store - }); - - return { - c() { - widget._fragment.c(); - }, - - m(target, anchor) { - widget._mount(target, anchor); - }, - - p: noop, - - d(detach) { - widget.destroy(detach); - } - }; -} - -function Main(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - - flush(this); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._recompute = noop; - -function noop() {} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/expected/widget/Widget.js b/test/cli/samples/dir-subdir/expected/widget/Widget.js deleted file mode 100644 index e63ac2dad7..0000000000 --- a/test/cli/samples/dir-subdir/expected/widget/Widget.js +++ /dev/null @@ -1,191 +0,0 @@ -/* src/widget/Widget.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var p; - - return { - c() { - p = createElement("p"); - p.textContent = "widget"; - }, - - m(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -function Widget(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Widget.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Widget.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function noop() {} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Widget; \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/src/Main.svelte b/test/cli/samples/dir-subdir/src/Main.svelte deleted file mode 100644 index ac663b4338..0000000000 --- a/test/cli/samples/dir-subdir/src/Main.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - - \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/src/widget/Widget.svelte b/test/cli/samples/dir-subdir/src/widget/Widget.svelte deleted file mode 100644 index 963b8f1a2a..0000000000 --- a/test/cli/samples/dir-subdir/src/widget/Widget.svelte +++ /dev/null @@ -1 +0,0 @@ -

widget

\ No newline at end of file diff --git a/test/cli/samples/dir/command.sh b/test/cli/samples/dir/command.sh deleted file mode 100644 index 10067cb1f9..0000000000 --- a/test/cli/samples/dir/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src -o actual \ No newline at end of file diff --git a/test/cli/samples/dir/expected/Main.js b/test/cli/samples/dir/expected/Main.js deleted file mode 100644 index d87ac37939..0000000000 --- a/test/cli/samples/dir/expected/Main.js +++ /dev/null @@ -1,185 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ -import Widget from './Widget.svelte'; - - - -function create_main_fragment(component, ctx) { - - var widget = new Widget({ - root: component.root, - store: component.store - }); - - return { - c() { - widget._fragment.c(); - }, - - m(target, anchor) { - widget._mount(target, anchor); - }, - - p: noop, - - d(detach) { - widget.destroy(detach); - } - }; -} - -function Main(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - - flush(this); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._recompute = noop; - -function noop() {} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; \ No newline at end of file diff --git a/test/cli/samples/dir/expected/Widget.js b/test/cli/samples/dir/expected/Widget.js deleted file mode 100644 index eeb37e3cfa..0000000000 --- a/test/cli/samples/dir/expected/Widget.js +++ /dev/null @@ -1,191 +0,0 @@ -/* src/Widget.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var p; - - return { - c() { - p = createElement("p"); - p.textContent = "widget"; - }, - - m(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -function Widget(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Widget.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Widget.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function noop() {} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Widget; \ No newline at end of file diff --git a/test/cli/samples/dir/src/Main.svelte b/test/cli/samples/dir/src/Main.svelte deleted file mode 100644 index 0a9d5bba87..0000000000 --- a/test/cli/samples/dir/src/Main.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - - \ No newline at end of file diff --git a/test/cli/samples/dir/src/Widget.svelte b/test/cli/samples/dir/src/Widget.svelte deleted file mode 100644 index 963b8f1a2a..0000000000 --- a/test/cli/samples/dir/src/Widget.svelte +++ /dev/null @@ -1 +0,0 @@ -

widget

\ No newline at end of file diff --git a/test/cli/samples/globals/command.sh b/test/cli/samples/globals/command.sh deleted file mode 100644 index 9e1a2de74a..0000000000 --- a/test/cli/samples/globals/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src/Main.svelte -f iife -g the-answer:theAnswer > actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/globals/expected/Main.js b/test/cli/samples/globals/expected/Main.js deleted file mode 100644 index 8e526b08bf..0000000000 --- a/test/cli/samples/globals/expected/Main.js +++ /dev/null @@ -1,219 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ -var Main = (function(answer) { "use strict"; - answer = (answer && answer.__esModule) ? answer["default"] : answer; - - function data() { - return { - answer: answer - }; -}; - - function create_main_fragment(component, ctx) { - var p, text0, text1; - - return { - c() { - p = createElement("p"); - text0 = createText("The answer is "); - text1 = createText(ctx.answer); - }, - - m(target, anchor) { - insert(target, p, anchor); - append(p, text0); - append(p, text1); - }, - - p(changed, ctx) { - if (changed.answer) { - setData(text1, ctx.answer); - } - }, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; - } - - function Main(options) { - init(this, options); - this._state = assign(data(), options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } - } - - assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - - Main.prototype._recompute = noop; - - function createElement(name) { - return document.createElement(name); - } - - function createText(data) { - return document.createTextNode(data); - } - - function insert(target, node, anchor) { - target.insertBefore(node, anchor); - } - - function append(target, node) { - target.appendChild(node); - } - - function setData(text, data) { - text.data = '' + data; - } - - function detachNode(node) { - node.parentNode.removeChild(node); - } - - function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } - } - - function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; - } - - function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; - } - - function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } - } - - function on(eventName, 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; - flush(this.root); - } - - function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } - } - - function _stage(newState) { - assign(this._staged, newState); - } - - function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); - } - - function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); - } - - function noop() {} - - function blankObject() { - return Object.create(null); - } - - function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; - } - - function callAll(fns) { - while (fns && fns.length) fns.shift()(); - } - return Main; -}(theAnswer)); \ No newline at end of file diff --git a/test/cli/samples/globals/src/Main.svelte b/test/cli/samples/globals/src/Main.svelte deleted file mode 100644 index 2fc0383a67..0000000000 --- a/test/cli/samples/globals/src/Main.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - -

The answer is {answer}

\ No newline at end of file diff --git a/test/cli/samples/sourcemap-inline/command.sh b/test/cli/samples/sourcemap-inline/command.sh deleted file mode 100644 index 073fa7d259..0000000000 --- a/test/cli/samples/sourcemap-inline/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src/Main.svelte -m inline -o actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/sourcemap-inline/expected/Main.js b/test/cli/samples/sourcemap-inline/expected/Main.js deleted file mode 100644 index 534c6734f2..0000000000 --- a/test/cli/samples/sourcemap-inline/expected/Main.js +++ /dev/null @@ -1,192 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var p; - - return { - c() { - p = createElement("p"); - p.textContent = "Hello world!"; - }, - - m(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -function Main(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function noop() {} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbi5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL01haW4uaHRtbCJdLCJzb3VyY2VzQ29udGVudCI6WyI8cD5IZWxsbyB3b3JsZCE8L3A+XG5cbjxzY3JpcHQ+XG5cdGV4cG9ydCBkZWZhdWx0IHtcblx0XHRvbnJlbmRlciAoKSB7XG5cdFx0XHRjb25zb2xlLmxvZyggJ2hlcmUnICk7XG5cdFx0fVxuXHR9O1xuPC9zY3JpcHQ+Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0= diff --git a/test/cli/samples/sourcemap-inline/src/Main.svelte b/test/cli/samples/sourcemap-inline/src/Main.svelte deleted file mode 100644 index 6f3f80bbff..0000000000 --- a/test/cli/samples/sourcemap-inline/src/Main.svelte +++ /dev/null @@ -1,9 +0,0 @@ - - -

Hello world!

\ No newline at end of file diff --git a/test/cli/samples/sourcemap/command.sh b/test/cli/samples/sourcemap/command.sh deleted file mode 100644 index 9164b1760c..0000000000 --- a/test/cli/samples/sourcemap/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src/Main.svelte -m -o actual/Main.js \ No newline at end of file diff --git a/test/cli/samples/sourcemap/expected/Main.js b/test/cli/samples/sourcemap/expected/Main.js deleted file mode 100644 index 59059aadcb..0000000000 --- a/test/cli/samples/sourcemap/expected/Main.js +++ /dev/null @@ -1,192 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var p; - - return { - c() { - p = createElement("p"); - p.textContent = "Hello world!"; - }, - - m(target, anchor) { - insert(target, p, anchor); - }, - - p: noop, - - d(detach) { - if (detach) { - detachNode(p); - } - } - }; -} - -function Main(options) { - init(this, options); - this._state = assign({}, options.data); - this._intro = true; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function noop() {} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; -//# sourceMappingURL=Main.js.map diff --git a/test/cli/samples/sourcemap/expected/Main.js.map b/test/cli/samples/sourcemap/expected/Main.js.map deleted file mode 100644 index a31dec16ab..0000000000 --- a/test/cli/samples/sourcemap/expected/Main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"Main.js","sources":["../src/Main.svelte"],"sourcesContent":["

Hello world!

\n\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"} \ No newline at end of file diff --git a/test/cli/samples/sourcemap/src/Main.svelte b/test/cli/samples/sourcemap/src/Main.svelte deleted file mode 100644 index 6f3f80bbff..0000000000 --- a/test/cli/samples/sourcemap/src/Main.svelte +++ /dev/null @@ -1,9 +0,0 @@ - - -

Hello world!

\ No newline at end of file diff --git a/test/cli/samples/ssr/command.sh b/test/cli/samples/ssr/command.sh deleted file mode 100644 index 878f6038ab..0000000000 --- a/test/cli/samples/ssr/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile --generate ssr src/Main.svelte > actual/Main.js diff --git a/test/cli/samples/ssr/expected/Main.js b/test/cli/samples/ssr/expected/Main.js deleted file mode 100644 index b7a4f4addf..0000000000 --- a/test/cli/samples/ssr/expected/Main.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; - -var Main = {}; - -Main.filename = "src/Main.svelte"; - -Main.data = function() { - return {}; -}; - -Main.render = function(state, options = {}) { - var components = new Set(); - - function addComponent(component) { - components.add(component); - } - - var result = { head: '', addComponent }; - var html = Main._render(result, state, options); - - var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n'); - - return { - html, - head: result.head, - css: { code: cssCode, map: null }, - toString() { - return html; - } - }; -} - -Main._render = function(__result, ctx, options) { - __result.addComponent(Main); - - ctx = Object.assign({}, ctx); - - return `

Hello world!

`; -}; - -Main.css = { - code: '', - map: null -}; - -var warned = false; - -module.exports = Main; \ No newline at end of file diff --git a/test/cli/samples/ssr/src/Main.svelte b/test/cli/samples/ssr/src/Main.svelte deleted file mode 100644 index aa994ea13e..0000000000 --- a/test/cli/samples/ssr/src/Main.svelte +++ /dev/null @@ -1 +0,0 @@ -

Hello world!

\ No newline at end of file diff --git a/test/cli/samples/store/command.sh b/test/cli/samples/store/command.sh deleted file mode 100644 index dedeae05ef..0000000000 --- a/test/cli/samples/store/command.sh +++ /dev/null @@ -1 +0,0 @@ -svelte compile src/Main.svelte --store > actual/Main.js diff --git a/test/cli/samples/store/expected/Main.js b/test/cli/samples/store/expected/Main.js deleted file mode 100644 index 28bc62b786..0000000000 --- a/test/cli/samples/store/expected/Main.js +++ /dev/null @@ -1,217 +0,0 @@ -/* src/Main.svelte generated by Svelte vx.y.z */ - -function create_main_fragment(component, ctx) { - var h1, text0, text1; - - return { - c() { - h1 = createElement("h1"); - text0 = createText("Hello "); - text1 = createText(ctx.$name); - }, - - m(target, anchor) { - insert(target, h1, anchor); - append(h1, text0); - append(h1, text1); - }, - - p(changed, ctx) { - if (changed.$name) { - setData(text1, ctx.$name); - } - }, - - d(detach) { - if (detach) { - detachNode(h1); - } - } - }; -} - -function Main(options) { - init(this, options); - this._state = assign(this.store._init(["name"]), options.data); - this.store._add(this, ["name"]); - this._intro = true; - - this._handlers.destroy = [removeFromStore]; - - this._fragment = create_main_fragment(this, this._state); - - if (options.target) { - this._fragment.c(); - this._mount(options.target, options.anchor); - } -} - -assign(Main.prototype, { - destroy: destroy, - get: get, - fire: fire, - on: on, - set: set, - _set: _set, - _stage: _stage, - _mount: _mount, - _differs: _differs - }); - -Main.prototype._recompute = noop; - -function createElement(name) { - return document.createElement(name); -} - -function createText(data) { - return document.createTextNode(data); -} - -function insert(target, node, anchor) { - target.insertBefore(node, anchor); -} - -function append(target, node) { - target.appendChild(node); -} - -function setData(text, data) { - text.data = '' + data; -} - -function detachNode(node) { - node.parentNode.removeChild(node); -} - -function init(component, options) { - component._handlers = blankObject(); - component._slots = blankObject(); - component._bind = options._bind; - component._staged = {}; - - component.options = options; - component.root = options.root || component; - component.store = options.store || component.root.store; - - if (!options.root) { - component._beforecreate = []; - component._oncreate = []; - component._aftercreate = []; - } -} - -function assign(tar, src) { - for (var k in src) tar[k] = src[k]; - return tar; -} - -function removeFromStore() { - this.store._remove(this); -} - -function destroy(detach) { - this.destroy = noop; - this.fire('destroy'); - this.set = noop; - - this._fragment.d(detach !== false); - this._fragment = null; - this._state = {}; -} - -function get() { - return 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) { - var handler = handlers[i]; - - if (!handler.__calling) { - try { - handler.__calling = true; - handler.call(this, data); - } finally { - handler.__calling = false; - } - } - } -} - -function on(eventName, 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; - flush(this.root); -} - -function _set(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - newState = assign(this._staged, newState); - this._staged = {}; - - for (var key in newState) { - if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; - } - if (!dirty) return; - - this._state = assign(assign({}, oldState), newState); - this._recompute(changed, this._state); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - this.fire("state", { changed: changed, current: this._state, previous: oldState }); - this._fragment.p(changed, this._state); - this.fire("update", { changed: changed, current: this._state, previous: oldState }); - } -} - -function _stage(newState) { - assign(this._staged, newState); -} - -function _mount(target, anchor) { - this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); -} - -function _differs(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); -} - -function noop() {} - -function blankObject() { - return Object.create(null); -} - -function flush(component) { - component._lock = true; - callAll(component._beforecreate); - callAll(component._oncreate); - callAll(component._aftercreate); - component._lock = false; -} - -function callAll(fns) { - while (fns && fns.length) fns.shift()(); -} -export default Main; \ No newline at end of file diff --git a/test/cli/samples/store/src/Main.svelte b/test/cli/samples/store/src/Main.svelte deleted file mode 100644 index 3010a856fb..0000000000 --- a/test/cli/samples/store/src/Main.svelte +++ /dev/null @@ -1 +0,0 @@ -

Hello {$name}

\ No newline at end of file diff --git a/test/cli/update.js b/test/cli/update.js deleted file mode 100644 index 468fe51f15..0000000000 --- a/test/cli/update.js +++ /dev/null @@ -1,20 +0,0 @@ -const sander = require('sander'); -const glob = require('tiny-glob/sync'); - -process.chdir(__dirname); - -sander.readdirSync('samples').forEach(dir => { - if (dir[0] === '.') return; - - sander.rimrafSync(`samples/${dir}/expected`); - - const files = glob(`**`, { cwd: `samples/${dir}/actual`, filesOnly: true }); - files.forEach(file => { - const source = sander.readFileSync(`samples/${dir}/actual/${file}`, { encoding: 'utf-8' }); - - sander.writeFileSync( - `samples/${dir}/expected/${file}`, - source.replace(/generated by Svelte v(\d+\.\d+\.\d+)/, 'generated by Svelte vx.y.z') - ); - }); -}); \ No newline at end of file diff --git a/test/parser/samples/if-block-elseif/input.svelte b/test/parser/samples/if-block-elseif/input.svelte index a3bd474af7..2566aef258 100644 --- a/test/parser/samples/if-block-elseif/input.svelte +++ b/test/parser/samples/if-block-elseif/input.svelte @@ -1,5 +1,5 @@ {#if x > 10}

x is greater than 10

-{:elseif x < 5} +{:else if x < 5}

x is less than 5

{/if} diff --git a/test/parser/samples/if-block-elseif/output.json b/test/parser/samples/if-block-elseif/output.json index 426e1f7fbc..188b57aaad 100644 --- a/test/parser/samples/if-block-elseif/output.json +++ b/test/parser/samples/if-block-elseif/output.json @@ -1,12 +1,12 @@ { "html": { "start": 0, - "end": 88, + "end": 89, "type": "Fragment", "children": [ { "start": 0, - "end": 88, + "end": 89, "type": "IfBlock", "expression": { "type": "BinaryExpression", @@ -45,45 +45,45 @@ } ], "else": { - "start": 57, - "end": 83, + "start": 58, + "end": 84, "type": "ElseBlock", "children": [ { - "start": 57, - "end": 88, + "start": 58, + "end": 89, "type": "IfBlock", "elseif": true, "expression": { "type": "BinaryExpression", - "start": 51, - "end": 56, + "start": 52, + "end": 57, "left": { "type": "Identifier", - "start": 51, - "end": 52, + "start": 52, + "end": 53, "name": "x" }, "operator": "<", "right": { "type": "Literal", - "start": 55, - "end": 56, + "start": 56, + "end": 57, "value": 5, "raw": "5" } }, "children": [ { - "start": 59, - "end": 82, + "start": 60, + "end": 83, "type": "Element", "name": "p", "attributes": [], "children": [ { - "start": 62, - "end": 78, + "start": 63, + "end": 79, "type": "Text", "data": "x is less than 5" } @@ -95,8 +95,5 @@ } } ] - }, - "css": null, - "instance": null, - "module": null + } } \ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-slot/main.svelte b/test/runtime/samples/dynamic-component-slot/main.svelte index 99bcf9e64f..ed357f4302 100644 --- a/test/runtime/samples/dynamic-component-slot/main.svelte +++ b/test/runtime/samples/dynamic-component-slot/main.svelte @@ -17,7 +17,7 @@ {#if foo}

foo

- {:elseif bar} + {:else if bar}

bar

{:else}

neither foo nor bar

diff --git a/test/runtime/samples/event-handler-destructured/_config.js b/test/runtime/samples/event-handler-destructured/_config.js new file mode 100644 index 0000000000..b32fe76c0a --- /dev/null +++ b/test/runtime/samples/event-handler-destructured/_config.js @@ -0,0 +1,15 @@ +export default { + html: ` + + `, + + async test({ assert, component, target, window }) { + const button = target.querySelector('button'); + const event = new window.MouseEvent('click'); + + await button.dispatchEvent(event); + assert.htmlEqual(target.innerHTML, ` + + `); + } +}; diff --git a/test/runtime/samples/event-handler-destructured/main.svelte b/test/runtime/samples/event-handler-destructured/main.svelte new file mode 100644 index 0000000000..d80c7ed15c --- /dev/null +++ b/test/runtime/samples/event-handler-destructured/main.svelte @@ -0,0 +1,16 @@ + + + \ No newline at end of file diff --git a/test/runtime/samples/if-block-elseif-no-else/main.svelte b/test/runtime/samples/if-block-elseif-no-else/main.svelte index a3bd474af7..2566aef258 100644 --- a/test/runtime/samples/if-block-elseif-no-else/main.svelte +++ b/test/runtime/samples/if-block-elseif-no-else/main.svelte @@ -1,5 +1,5 @@ {#if x > 10}

x is greater than 10

-{:elseif x < 5} +{:else if x < 5}

x is less than 5

{/if} diff --git a/test/runtime/samples/if-block-elseif-text/main.svelte b/test/runtime/samples/if-block-elseif-text/main.svelte index 43ac545677..ea1e1aac43 100644 --- a/test/runtime/samples/if-block-elseif-text/main.svelte +++ b/test/runtime/samples/if-block-elseif-text/main.svelte @@ -1 +1 @@ -before-{#if x > 10}if{:elseif x < 5}elseif{:else}else{/if}-after +before-{#if x > 10}if{:else if x < 5}elseif{:else}else{/if}-after diff --git a/test/runtime/samples/if-block-elseif/main.svelte b/test/runtime/samples/if-block-elseif/main.svelte index ffa5879943..d4833c7aeb 100644 --- a/test/runtime/samples/if-block-elseif/main.svelte +++ b/test/runtime/samples/if-block-elseif/main.svelte @@ -1,6 +1,6 @@ {#if x > 10}

x is greater than 10

-{:elseif x < 5} +{:else if x < 5}

x is less than 5

{:else}

x is between 5 and 10

diff --git a/test/runtime/samples/if-block-outro-nested-else/main.svelte b/test/runtime/samples/if-block-outro-nested-else/main.svelte index 3937998c40..8b8f599e4f 100644 --- a/test/runtime/samples/if-block-outro-nested-else/main.svelte +++ b/test/runtime/samples/if-block-outro-nested-else/main.svelte @@ -7,7 +7,7 @@ {#if foo} {#if false} - {:elseif false} + {:else if false} {/if} {/if} diff --git a/test/runtime/samples/prop-subscribable/_config.js b/test/runtime/samples/prop-subscribable/_config.js new file mode 100644 index 0000000000..69f8104fab --- /dev/null +++ b/test/runtime/samples/prop-subscribable/_config.js @@ -0,0 +1,11 @@ +import { writable } from '../../../../store.js'; + +export default { + props: { + b: writable(42) + }, + + html: ` + 42 + ` +}; \ No newline at end of file diff --git a/test/runtime/samples/prop-subscribable/main.svelte b/test/runtime/samples/prop-subscribable/main.svelte new file mode 100644 index 0000000000..6721635efd --- /dev/null +++ b/test/runtime/samples/prop-subscribable/main.svelte @@ -0,0 +1,7 @@ + + +{$b} \ No newline at end of file diff --git a/test/runtime/samples/transition-js-if-elseif-block-outro/main.svelte b/test/runtime/samples/transition-js-if-elseif-block-outro/main.svelte index 462e073bd7..99c535dca2 100644 --- a/test/runtime/samples/transition-js-if-elseif-block-outro/main.svelte +++ b/test/runtime/samples/transition-js-if-elseif-block-outro/main.svelte @@ -17,6 +17,6 @@ {#if x}
yes
-{:elseif y} +{:else if y}
no
{/if} \ No newline at end of file diff --git a/test/store/index.js b/test/store/index.js index f4f89bf9a8..0bf3ee93e0 100644 --- a/test/store/index.js +++ b/test/store/index.js @@ -1,5 +1,5 @@ import * as assert from 'assert'; -import { readable, writable, derive } from '../../store.js'; +import { readable, writable, derive, get } from '../../store.js'; describe('store', () => { describe('writable', () => { @@ -172,4 +172,11 @@ describe('store', () => { unsubscribe(); }); }); + + describe('get', () => { + it('gets the current value of a store', () => { + const store = readable(() => {}, 42); + assert.equal(get(store), 42); + }); + }); }); diff --git a/test/vars/index.js b/test/vars/index.js index d8da8e4778..66ffd94c70 100644 --- a/test/vars/index.js +++ b/test/vars/index.js @@ -14,47 +14,41 @@ describe('vars', () => { throw new Error('Forgot to remove `solo: true` from test'); } - (solo ? it.only : skip ? it.skip : it)(dir, () => { - const config = loadConfig(`./vars/samples/${dir}/_config.js`); - const filename = `test/vars/samples/${dir}/input.svelte`; - const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, ''); - - const expectedError = tryToLoadJson( - `test/vars/samples/${dir}/error.json` - ); - - let result; - let error; - - try { - result = svelte.compile(input, config.options); - config.test(assert, result.vars); - } catch (e) { - error = e; - } - - if (error || expectedError) { - if (error && !expectedError) { - throw error; + for (const generate of ['dom', 'ssr', false]) { + (solo ? it.only : skip ? it.skip : it)(`${dir}, generate: ${generate}`, () => { + const config = loadConfig(`./vars/samples/${dir}/_config.js`); + const filename = `test/vars/samples/${dir}/input.svelte`; + const input = fs.readFileSync(filename, 'utf-8').replace(/\s+$/, ''); + + const expectedError = tryToLoadJson( + `test/vars/samples/${dir}/error.json` + ); + + let result; + let error; + + try { + result = svelte.compile(input, { ...config.options, generate }); + config.test(assert, result.vars); + } catch (e) { + error = e; } - if (expectedError && !error) { - throw new Error(`Expected an error: ${expectedError.message}`); - } - - assert.equal(error.message, expectedError.message); - assert.deepEqual(error.start, expectedError.start); - assert.deepEqual(error.end, expectedError.end); - assert.equal(error.pos, expectedError.pos); - } - }); - }); + if (error || expectedError) { + if (error && !expectedError) { + throw error; + } - it('returns a vars object when options.generate is false', () => { - const { vars } = svelte.compile('', { - generate: false - }); + if (expectedError && !error) { + throw new Error(`Expected an error: ${expectedError.message}`); + } - assert.ok(Array.isArray(vars)); + assert.equal(error.message, expectedError.message); + assert.deepEqual(error.start, expectedError.start); + assert.deepEqual(error.end, expectedError.end); + assert.equal(error.pos, expectedError.pos); + } + }); + } }); }); diff --git a/test/vars/samples/actions/_config.js b/test/vars/samples/actions/_config.js new file mode 100644 index 0000000000..2cda8889c9 --- /dev/null +++ b/test/vars/samples/actions/_config.js @@ -0,0 +1,16 @@ +export default { + test(assert, vars) { + assert.deepEqual(vars, [ + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'foo', + reassigned: false, + referenced: true, + writable: true + } + ]); + } +}; diff --git a/test/vars/samples/actions/input.svelte b/test/vars/samples/actions/input.svelte new file mode 100644 index 0000000000..fe614c760c --- /dev/null +++ b/test/vars/samples/actions/input.svelte @@ -0,0 +1,5 @@ + + +
diff --git a/test/vars/samples/animations/_config.js b/test/vars/samples/animations/_config.js new file mode 100644 index 0000000000..2cda8889c9 --- /dev/null +++ b/test/vars/samples/animations/_config.js @@ -0,0 +1,16 @@ +export default { + test(assert, vars) { + assert.deepEqual(vars, [ + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'foo', + reassigned: false, + referenced: true, + writable: true + } + ]); + } +}; diff --git a/test/vars/samples/animations/input.svelte b/test/vars/samples/animations/input.svelte new file mode 100644 index 0000000000..7843ab928d --- /dev/null +++ b/test/vars/samples/animations/input.svelte @@ -0,0 +1,7 @@ + + +{#each [] as x (x)} +
+{/each} diff --git a/test/vars/samples/transitions/_config.js b/test/vars/samples/transitions/_config.js new file mode 100644 index 0000000000..e42faf7d19 --- /dev/null +++ b/test/vars/samples/transitions/_config.js @@ -0,0 +1,36 @@ +export default { + test(assert, vars) { + assert.deepEqual(vars, [ + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'foo', + reassigned: false, + referenced: true, + writable: true + }, + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'bar', + reassigned: false, + referenced: true, + writable: true + }, + { + export_name: null, + injected: false, + module: false, + mutated: false, + name: 'baz', + reassigned: false, + referenced: true, + writable: true + } + ]); + } +}; diff --git a/test/vars/samples/transitions/input.svelte b/test/vars/samples/transitions/input.svelte new file mode 100644 index 0000000000..1dac9bc5ec --- /dev/null +++ b/test/vars/samples/transitions/input.svelte @@ -0,0 +1,9 @@ + + +
+
+