diff --git a/.gitignore b/.gitignore index ed21efb721..25a75902db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ .DS_Store .nyc_output node_modules +/cli/ /compiler/ /ssr/ /shared.js /scratch/ /coverage/ /coverage.lcov/ +/test/cli/samples/*/actual /test/sourcemaps/samples/*/output.js /test/sourcemaps/samples/*/output.js.map /src/compile/shared.ts diff --git a/package.json b/package.json index 651cda4a81..7a035dfc3e 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,17 @@ "version": "2.3.0", "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", + "bin": { + "svelte": "svelte" + }, "files": [ + "cli", "compiler", "ssr", "shared.js", "store.js", "store.umd.js", + "svelte", "README.md" ], "scripts": { @@ -48,6 +53,7 @@ "acorn": "^5.4.1", "acorn-dynamic-import": "^3.0.0", "chalk": "^2.4.0", + "clorox": "^1.0.3", "codecov": "^3.0.0", "console-group": "^0.3.2", "css-tree": "1.0.0-alpha22", @@ -55,7 +61,6 @@ "eslint-plugin-html": "^4.0.3", "eslint-plugin-import": "^2.11.0", "estree-walker": "^0.5.1", - "glob": "^7.1.1", "is-reference": "^1.1.0", "jsdom": "^11.8.0", "locate-character": "^2.0.5", @@ -75,8 +80,11 @@ "rollup-plugin-typescript": "^0.8.1", "rollup-plugin-virtual": "^1.0.1", "rollup-watch": "^4.3.1", + "sade": "^1.4.0", + "sander": "^0.6.0", "source-map": "0.6", "source-map-support": "^0.5.4", + "tiny-glob": "^0.2.0", "ts-node": "^6.0.0", "tslib": "^1.8.0", "typescript": "^2.8.3" diff --git a/rollup.config.js b/rollup.config.js index 5ad189694b..59e883b26c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -57,6 +57,29 @@ export default [ } }, + /* cli/*.js */ + { + input: ['src/cli/index.ts'], + output: { + dir: 'cli', + format: 'cjs' + }, + external: ['fs', 'path', 'os', 'svelte'], + paths: { + svelte: '../compiler/svelte.js' + }, + plugins: [ + json(), + commonjs(), + resolve(), + typescript({ + typescript: require('typescript') + }) + ], + experimentalDynamicImport: true, + experimentalCodeSplitting: true + }, + /* shared.js */ { input: 'src/shared/index.js', diff --git a/src/cli/compile.ts b/src/cli/compile.ts new file mode 100644 index 0000000000..0b145be1e0 --- /dev/null +++ b/src/cli/compile.ts @@ -0,0 +1,139 @@ +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 globals = {}; + if (opts.globals) { + opts.globals.split(',').forEach(pair => { + const [key, value] = pair.split(':'); + globals[key] = value; + }); + } + + const options = { + name: opts.name, + format: opts.format, + sourceMap: opts.sourcemap, + globals, + css: opts.css !== false, + dev: opts.dev, + immutable: opts.immutable, + generate: opts.generate || 'dom', + customElement: opts.customElement, + store: opts.store + }; + + if (isDir) { + mkdirp(output); + compileDirectory(input, output, options); + } else { + compileFile(input, output, options); + } +} + +function compileDirectory(input, output, options) { + 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 + ); + } else { + const stats = fs.statSync(src); + if (stats.isDirectory()) { + compileDirectory(src, dest, options); + } + } + }); +} + +let SOURCEMAPPING_URL = 'sourceMa'; +SOURCEMAPPING_URL += 'ppingURL'; + +function compileFile(input, output, options) { + 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 { sourceMap } = options; + 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 } = compiled; + + 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 new file mode 100644 index 0000000000..b7ca813716 --- /dev/null +++ b/src/cli/error.ts @@ -0,0 +1,17 @@ +import clorox from 'clorox'; + +function stderr(msg) { + console.error(msg); // eslint-disable-line no-console +} + +export default function error(err) { + stderr(`${clorox.red(err.message || err)}`); + + if (err.frame) { + stderr(err.frame); // eslint-disable-line no-console + } else if (err.stack) { + stderr(`${clorox.grey(err.stack)}`); + } + + process.exit(1); +} diff --git a/src/cli/index.ts b/src/cli/index.ts new file mode 100644 index 0000000000..411d7f2f1d --- /dev/null +++ b/src/cli/index.ts @@ -0,0 +1,30 @@ +import sade from 'sade'; +import * as pkg from '../../package.json'; + +const prog = sade('svelte-cli').version(pkg.version); + +prog + .command('compile ') + + .option('-o, --output', 'Output (if absent, prints to stdout)') + .option('-f, --format', 'Type of output (amd, cjs, es, iife, umd)') + .option('-g, --globals', 'Comma-separate list of `module ID:Global` pairs') + .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('--amdId', 'ID for AMD module (default is anonymous)') + .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') + + .example('compile App.html > App.js') + .example('compile src -o dest') + .example('compile -f umd MyComponent.html > MyComponent.js') + + .action((input, opts) => { + import('./compile.js').then(({ compile }) => { + compile(input, opts); + }); + }) + + .parse(process.argv); \ No newline at end of file diff --git a/svelte b/svelte new file mode 100755 index 0000000000..527222ef56 --- /dev/null +++ b/svelte @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('./cli/index.ts.js'); \ No newline at end of file diff --git a/test/cli/index.js b/test/cli/index.js new file mode 100644 index 0000000000..f2b89c63c2 --- /dev/null +++ b/test/cli/index.js @@ -0,0 +1,82 @@ +const fs = require('fs'); +const path = require('path'); +const child_process = require('child_process'); +const assert = require('assert'); +const glob = require('tiny-glob/sync.js'); + +const bin = path.resolve(`svelte`); + +function normalize(str) { + return str + .replace(/^\s+$/gm, '') + .replace(/generated by Svelte v[.\d]+/, `generated by Svelte vx.y.z`) + .trim(); +} + +const cwd = process.cwd(); + +describe('svelte-cli', () => { + 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'); + + child_process.exec(` + alias svelte=${bin} + mkdir -p actual + rm -rf actual/* + ${command} + `, (err, stdout, stderr) => { + if (err) { + done(err); + 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') + ) + }; + }); + + console.log(actual); + console.log(expected); + + 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 new file mode 100644 index 0000000000..0ae80e4c95 --- /dev/null +++ b/test/cli/samples/basic/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html > actual/Main.js diff --git a/test/cli/samples/basic/expected/Main.js b/test/cli/samples/basic/expected/Main.js new file mode 100644 index 0000000000..6514bbbd31 --- /dev/null +++ b/test/cli/samples/basic/expected/Main.js @@ -0,0 +1,173 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "Hello world!"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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/basic/src/Main.html b/test/cli/samples/basic/src/Main.html new file mode 100644 index 0000000000..aa994ea13e --- /dev/null +++ b/test/cli/samples/basic/src/Main.html @@ -0,0 +1 @@ +

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 new file mode 100644 index 0000000000..b93c2cb16a --- /dev/null +++ b/test/cli/samples/custom-element/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html --customElement > actual/Main.js diff --git a/test/cli/samples/custom-element/expected/Main.js b/test/cli/samples/custom-element/expected/Main.js new file mode 100644 index 0000000000..e92ada81cd --- /dev/null +++ b/test/cli/samples/custom-element/expected/Main.js @@ -0,0 +1,198 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "Hello world!"; + this.c = noop; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +class Main extends HTMLElement { + constructor(options = {}) { + super(); + init(this, options); + this._state = assign({}, options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); +assign(Main.prototype, { + _mount(target, anchor) { + target.insertBefore(this, anchor); + }, + + _unmount() { + this.parentNode.removeChild(this); + } +}); + +customElements.define("my-element", Main); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function noop() {} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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/custom-element/src/Main.html b/test/cli/samples/custom-element/src/Main.html new file mode 100644 index 0000000000..c6083164d4 --- /dev/null +++ b/test/cli/samples/custom-element/src/Main.html @@ -0,0 +1,7 @@ +

Hello world!

+ + \ No newline at end of file diff --git a/test/cli/samples/dev/command.sh b/test/cli/samples/dev/command.sh new file mode 100644 index 0000000000..37d9b87fc0 --- /dev/null +++ b/test/cli/samples/dev/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html -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 new file mode 100644 index 0000000000..401307fe2e --- /dev/null +++ b/test/cli/samples/dev/expected/Main.js @@ -0,0 +1,197 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c: function create() { + p = createElement("p"); + p.textContent = "Hello world!"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + detachNode(p); + }, + + d: noop + }; +} + +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._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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._checkReadOnly = function _checkReadOnly(newState) { +}; + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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) { + handler.__calling = true; + handler.call(this, data); + 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; + + 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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = null; + this._state = {}; +} + +function set(newState) { + this._set(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function 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.html b/test/cli/samples/dev/src/Main.html new file mode 100644 index 0000000000..aa994ea13e --- /dev/null +++ b/test/cli/samples/dev/src/Main.html @@ -0,0 +1 @@ +

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 new file mode 100644 index 0000000000..37089f3f44 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/command.sh @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..7cdd41dd4a --- /dev/null +++ b/test/cli/samples/dir-sourcemap/expected/Main.js @@ -0,0 +1,181 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +import Widget from './Widget.html'; + + + +function create_main_fragment(component, ctx) { + + var widget = new Widget({ + root: component.root + }); + + return { + c() { + widget._fragment.c(); + }, + + m(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u() { + widget._unmount(); + }, + + d() { + widget.destroy(false); + } + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function noop() {} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} +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 new file mode 100644 index 0000000000..cf890d4435 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/expected/Main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Main.js","sources":["../src/Main.html"],"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 new file mode 100644 index 0000000000..ad16d7aef5 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/expected/Widget.js @@ -0,0 +1,174 @@ +/* src/Widget.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Widget(options) { + init(this, options); + this._state = assign({}, options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Widget.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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 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 new file mode 100644 index 0000000000..d007680a81 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/expected/Widget.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Widget.js","sources":["../src/Widget.html"],"sourcesContent":["

widget

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

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 new file mode 100644 index 0000000000..10067cb1f9 --- /dev/null +++ b/test/cli/samples/dir-subdir/command.sh @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..52c9caf092 --- /dev/null +++ b/test/cli/samples/dir-subdir/expected/Main.js @@ -0,0 +1,180 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +import Widget from './widget/Widget.html'; + + + +function create_main_fragment(component, ctx) { + + var widget = new Widget({ + root: component.root + }); + + return { + c() { + widget._fragment.c(); + }, + + m(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u() { + widget._unmount(); + }, + + d() { + widget.destroy(false); + } + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function noop() {} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} +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 new file mode 100644 index 0000000000..66543c808e --- /dev/null +++ b/test/cli/samples/dir-subdir/expected/widget/Widget.js @@ -0,0 +1,173 @@ +/* src/widget/Widget.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Widget(options) { + init(this, options); + this._state = assign({}, options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Widget.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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 Widget; \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/src/Main.html b/test/cli/samples/dir-subdir/src/Main.html new file mode 100644 index 0000000000..01fdc800d7 --- /dev/null +++ b/test/cli/samples/dir-subdir/src/Main.html @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/test/cli/samples/dir-subdir/src/widget/Widget.html b/test/cli/samples/dir-subdir/src/widget/Widget.html new file mode 100644 index 0000000000..963b8f1a2a --- /dev/null +++ b/test/cli/samples/dir-subdir/src/widget/Widget.html @@ -0,0 +1 @@ +

widget

\ No newline at end of file diff --git a/test/cli/samples/dir/command.sh b/test/cli/samples/dir/command.sh new file mode 100644 index 0000000000..10067cb1f9 --- /dev/null +++ b/test/cli/samples/dir/command.sh @@ -0,0 +1 @@ +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 new file mode 100644 index 0000000000..77a56bf3bf --- /dev/null +++ b/test/cli/samples/dir/expected/Main.js @@ -0,0 +1,180 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +import Widget from './Widget.html'; + + + +function create_main_fragment(component, ctx) { + + var widget = new Widget({ + root: component.root + }); + + return { + c() { + widget._fragment.c(); + }, + + m(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u() { + widget._unmount(); + }, + + d() { + widget.destroy(false); + } + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this, this._state); + + if (options.target) { + this._fragment.c(); + this._mount(options.target, options.anchor); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(Main.prototype, { + destroy: destroy, + get: get, + fire: fire, + on: on, + set: set, + _set: _set, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function noop() {} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function assign(tar, src) { + for (var k in src) tar[k] = src[k]; + return tar; +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +function _differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +function blankObject() { + return Object.create(null); +} +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 new file mode 100644 index 0000000000..ecb3303e7d --- /dev/null +++ b/test/cli/samples/dir/expected/Widget.js @@ -0,0 +1,173 @@ +/* src/Widget.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Widget(options) { + init(this, options); + this._state = assign({}, options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Widget.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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 Widget; \ No newline at end of file diff --git a/test/cli/samples/dir/src/Main.html b/test/cli/samples/dir/src/Main.html new file mode 100644 index 0000000000..0f123bb0cb --- /dev/null +++ b/test/cli/samples/dir/src/Main.html @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/test/cli/samples/dir/src/Widget.html b/test/cli/samples/dir/src/Widget.html new file mode 100644 index 0000000000..963b8f1a2a --- /dev/null +++ b/test/cli/samples/dir/src/Widget.html @@ -0,0 +1 @@ +

widget

\ No newline at end of file diff --git a/test/cli/samples/globals/command.sh b/test/cli/samples/globals/command.sh new file mode 100644 index 0000000000..9ed0c2a844 --- /dev/null +++ b/test/cli/samples/globals/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html -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 new file mode 100644 index 0000000000..2db0a261a2 --- /dev/null +++ b/test/cli/samples/globals/expected/Main.js @@ -0,0 +1,197 @@ +/* src/Main.html generated by Svelte v2.3.0 */ +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, text, text_1; + + return { + c() { + p = createElement("p"); + text = createText("The answer is "); + text_1 = createText(ctx.answer); + }, + + m(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + }, + + p(changed, ctx) { + if (changed.answer) { + text_1.data = ctx.answer; + } + }, + + u() { + detachNode(p); + }, + + d: noop + }; + } + + function Main(options) { + init(this, options); + this._state = assign(data(), options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + + Main.prototype._recompute = noop; + + function createElement(name) { + return document.createElement(name); + } + + function createText(data) { + return document.createTextNode(data); + } + + function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); + } + + function appendNode(node, target) { + target.appendChild(node); + } + + function detachNode(node) { + node.parentNode.removeChild(node); + } + + function noop() {} + + function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; + } + + 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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; + } + + function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); + } + + function _unmount() { + if (this._fragment) this._fragment.u(); + } + + 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()(); + } + return Main; +}(theAnswer)); \ No newline at end of file diff --git a/test/cli/samples/globals/src/Main.html b/test/cli/samples/globals/src/Main.html new file mode 100644 index 0000000000..053f2ec0f6 --- /dev/null +++ b/test/cli/samples/globals/src/Main.html @@ -0,0 +1,13 @@ +

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 new file mode 100644 index 0000000000..36b5b71b8d --- /dev/null +++ b/test/cli/samples/sourcemap-inline/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html -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 new file mode 100644 index 0000000000..fe639ac270 --- /dev/null +++ b/test/cli/samples/sourcemap-inline/expected/Main.js @@ -0,0 +1,174 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "Hello world!"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWFpbi5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL01haW4uaHRtbCJdLCJzb3VyY2VzQ29udGVudCI6WyI8cD5IZWxsbyB3b3JsZCE8L3A+XG5cbjxzY3JpcHQ+XG5cdGV4cG9ydCBkZWZhdWx0IHtcblx0XHRvbnJlbmRlciAoKSB7XG5cdFx0XHRjb25zb2xlLmxvZyggJ2hlcmUnICk7XG5cdFx0fVxuXHR9O1xuPC9zY3JpcHQ+Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0= diff --git a/test/cli/samples/sourcemap-inline/src/Main.html b/test/cli/samples/sourcemap-inline/src/Main.html new file mode 100644 index 0000000000..944b54efb9 --- /dev/null +++ b/test/cli/samples/sourcemap-inline/src/Main.html @@ -0,0 +1,9 @@ +

Hello world!

+ + \ No newline at end of file diff --git a/test/cli/samples/sourcemap/command.sh b/test/cli/samples/sourcemap/command.sh new file mode 100644 index 0000000000..4309d50b89 --- /dev/null +++ b/test/cli/samples/sourcemap/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html -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 new file mode 100644 index 0000000000..4f303ce506 --- /dev/null +++ b/test/cli/samples/sourcemap/expected/Main.js @@ -0,0 +1,174 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var p; + + return { + c() { + p = createElement("p"); + p.textContent = "Hello world!"; + }, + + m(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u() { + detachNode(p); + }, + + d: noop + }; +} + +function Main(options) { + init(this, options); + this._state = assign({}, options.data); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function noop() {} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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/sourcemap/expected/Main.js.map b/test/cli/samples/sourcemap/expected/Main.js.map new file mode 100644 index 0000000000..5133d81436 --- /dev/null +++ b/test/cli/samples/sourcemap/expected/Main.js.map @@ -0,0 +1 @@ +{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["

Hello world!

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

Hello world!

+ + \ No newline at end of file diff --git a/test/cli/samples/ssr/command.sh b/test/cli/samples/ssr/command.sh new file mode 100644 index 0000000000..30e155691a --- /dev/null +++ b/test/cli/samples/ssr/command.sh @@ -0,0 +1 @@ +svelte compile --generate ssr src/Main.html > actual/Main.js diff --git a/test/cli/samples/ssr/expected/Main.js b/test/cli/samples/ssr/expected/Main.js new file mode 100644 index 0000000000..adf4e19fa0 --- /dev/null +++ b/test/cli/samples/ssr/expected/Main.js @@ -0,0 +1,48 @@ +"use strict"; + +var Main = {}; + +Main.filename = "src/Main.html"; + +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.html b/test/cli/samples/ssr/src/Main.html new file mode 100644 index 0000000000..aa994ea13e --- /dev/null +++ b/test/cli/samples/ssr/src/Main.html @@ -0,0 +1 @@ +

Hello world!

\ No newline at end of file diff --git a/test/cli/samples/store/command.sh b/test/cli/samples/store/command.sh new file mode 100644 index 0000000000..a734fdc772 --- /dev/null +++ b/test/cli/samples/store/command.sh @@ -0,0 +1 @@ +svelte compile src/Main.html --store > actual/Main.js diff --git a/test/cli/samples/store/expected/Main.js b/test/cli/samples/store/expected/Main.js new file mode 100644 index 0000000000..3588e60789 --- /dev/null +++ b/test/cli/samples/store/expected/Main.js @@ -0,0 +1,195 @@ +/* src/Main.html generated by Svelte v2.3.0 */ + +function create_main_fragment(component, ctx) { + var h1, text, text_1; + + return { + c() { + h1 = createElement("h1"); + text = createText("Hello "); + text_1 = createText(ctx.$name); + }, + + m(target, anchor) { + insertNode(h1, target, anchor); + appendNode(text, h1); + appendNode(text_1, h1); + }, + + p(changed, ctx) { + if (changed.$name) { + text_1.data = ctx.$name; + } + }, + + u() { + detachNode(h1); + }, + + d: noop + }; +} + +function Main(options) { + init(this, options); + this._state = assign(this.store._init(["name"]), options.data); + this.store._add(this, ["name"]); + + 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, + _mount: _mount, + _unmount: _unmount, + _differs: _differs + }); + +Main.prototype._recompute = noop; + +function createElement(name) { + return document.createElement(name); +} + +function createText(data) { + return document.createTextNode(data); +} + +function insertNode(node, target, anchor) { + target.insertBefore(node, anchor); +} + +function appendNode(node, target) { + target.appendChild(node); +} + +function detachNode(node) { + node.parentNode.removeChild(node); +} + +function noop() {} + +function init(component, options) { + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +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; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + 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) { + handler.__calling = true; + handler.call(this, data); + 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; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (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 _mount(target, anchor) { + this._fragment[this._fragment.i ? 'i' : 'm'](target, anchor || null); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +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/store/src/Main.html b/test/cli/samples/store/src/Main.html new file mode 100644 index 0000000000..3010a856fb --- /dev/null +++ b/test/cli/samples/store/src/Main.html @@ -0,0 +1 @@ +

Hello {$name}

\ No newline at end of file diff --git a/test/cli/update.js b/test/cli/update.js new file mode 100644 index 0000000000..bc87c18bff --- /dev/null +++ b/test/cli/update.js @@ -0,0 +1,10 @@ +const sander = require('sander'); + +process.chdir(__dirname); + +sander.readdirSync('samples').forEach(dir => { + if (dir[0] === '.') return; + + sander.rimrafSync(`samples/${dir}/expected`); + sander.copydirSync(`samples/${dir}/actual`).to(`samples/${dir}/expected`); +}); \ No newline at end of file diff --git a/test/helpers.js b/test/helpers.js index 0f0a1fd4ae..7a5bdf55e1 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -1,7 +1,7 @@ import jsdom from 'jsdom'; import { JSDOM } from 'jsdom'; import assert from 'assert'; -import glob from 'glob'; +import glob from 'tiny-glob/sync.js'; import fs from 'fs'; import path from 'path'; import chalk from 'chalk'; @@ -175,7 +175,7 @@ function capitalise(str) { } export function showOutput(cwd, options = {}, compile = svelte.compile) { - glob.sync('**/*.html', { cwd }).forEach(file => { + glob('**/*.html', { cwd }).forEach(file => { if (file[0] === '_') return; const name = path.basename(file) diff --git a/test/js/update.js b/test/js/update.js index a22e4a08b5..d50eb9780e 100644 --- a/test/js/update.js +++ b/test/js/update.js @@ -2,9 +2,9 @@ // their _actual equivalents. Only use it when you're sure that you haven't // broken anything! const fs = require("fs"); -const glob = require("glob"); +const glob = require("tiny-glob/sync.js"); -glob.sync("samples/*/_actual*", { cwd: __dirname }).forEach(file => { +glob("samples/*/_actual*", { cwd: __dirname }).forEach(file => { const actual = fs.readFileSync(`${__dirname}/${file}`, "utf-8"); fs.writeFileSync( `${__dirname}/${file.replace("_actual", "expected")}`, diff --git a/test/parser/update.js b/test/parser/update.js index 7c8e89ab76..78aa191b65 100644 --- a/test/parser/update.js +++ b/test/parser/update.js @@ -2,9 +2,9 @@ // their _actual equivalents. Only use it when you're sure that you haven't // broken anything! const fs = require("fs"); -const glob = require("glob"); +const glob = require("tiny-glob/sync.js"); -glob.sync("samples/*/_actual.json", { cwd: __dirname }).forEach(file => { +glob("samples/*/_actual.json", { cwd: __dirname }).forEach(file => { const actual = fs.readFileSync(`${__dirname}/${file}`, "utf-8"); fs.writeFileSync( `${__dirname}/${file.replace("_actual", "output")}`, diff --git a/test/server-side-rendering/index.js b/test/server-side-rendering/index.js index 1987d8215d..1d3aaa6825 100644 --- a/test/server-side-rendering/index.js +++ b/test/server-side-rendering/index.js @@ -1,7 +1,7 @@ import assert from "assert"; import * as fs from "fs"; import * as path from "path"; -import glob from 'glob'; +import glob from 'tiny-glob/sync.js'; import { showOutput, @@ -105,7 +105,7 @@ describe("ssr", () => { (config.skip ? it.skip : config.solo ? it.only : it)(dir, () => { const cwd = path.resolve("test/runtime/samples", dir); - glob.sync('**/*.html', { cwd: `test/runtime/samples/${dir}` }).forEach(file => { + glob('**/*.html', { cwd: `test/runtime/samples/${dir}` }).forEach(file => { const resolved = require.resolve(`../runtime/samples/${dir}/${file}`); delete require.cache[resolved]; }); diff --git a/test/test.js b/test/test.js index b501fd81a0..9bf09879b2 100644 --- a/test/test.js +++ b/test/test.js @@ -1,11 +1,11 @@ -const glob = require("glob"); +const glob = require("tiny-glob/sync.js"); require("./setup"); -glob.sync("**/__test__.js", { cwd: "src" }).forEach(function(file) { +glob("**/__test__.js", { cwd: "src" }).forEach(function(file) { require("../src/" + file); }); -glob.sync("*/index.js", { cwd: "test" }).forEach(function(file) { +glob("*/index.js", { cwd: "test" }).forEach(function(file) { require("./" + file); }); diff --git a/yarn.lock b/yarn.lock index 758125ff4a..282503ed1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -570,6 +570,10 @@ clone@^1.0.2: version "1.0.4" resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" +clorox@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/clorox/-/clorox-1.0.3.tgz#6fa63653f280c33d69f548fb14d239ddcfa1590d" + co@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" @@ -1427,7 +1431,7 @@ glob@7.1.1: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1, glob@^7.1.2: +glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" dependencies: @@ -1446,6 +1450,10 @@ globals@^9.18.0: version "9.18.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" +globalyzer@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.0.tgz#cb76da79555669a1519d5a8edf093afaa0bf1465" + globby@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/globby/-/globby-5.0.0.tgz#ebd84667ca0dbb330b99bcfc68eac2bc54370e0d" @@ -1457,7 +1465,11 @@ globby@^5.0.0: pify "^2.0.0" pinkie-promise "^2.0.0" -graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9: +globrex@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.0.2.tgz#9fbdfeee1e3edd878d61ebda19fa57a999850ca4" + +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" @@ -2419,6 +2431,10 @@ mocha@3: mkdirp "0.5.1" supports-color "3.1.2" +mri@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.0.tgz#5c0a3f29c8ccffbbb1ec941dcec09d71fa32f36a" + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -2719,6 +2735,12 @@ p-try@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" +pad-right@^0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/pad-right/-/pad-right-0.2.2.tgz#6fbc924045d244f2a2a244503060d3bfc6009774" + dependencies: + repeat-string "^1.5.2" + parse-glob@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c" @@ -3131,7 +3153,7 @@ right-align@^0.1.1: dependencies: align-text "^0.1.1" -rimraf@^2.2.8, rimraf@^2.4.3, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: +rimraf@^2.2.8, rimraf@^2.4.3, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" dependencies: @@ -3234,6 +3256,13 @@ rx-lite@*, rx-lite@^4.0.8: version "4.0.8" resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444" +sade@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/sade/-/sade-1.4.0.tgz#51874eb18600aa54ee39c8f566c2f4c999a7cd47" + dependencies: + mri "^1.1.0" + pad-right "^0.2.2" + safe-buffer@^5.0.1, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" @@ -3248,6 +3277,14 @@ safer-buffer@^2.1.0: version "2.1.2" resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" +sander@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/sander/-/sander-0.6.0.tgz#af1624cd7fb6dfad98ebef565319f920078da925" + dependencies: + graceful-fs "^4.1.3" + mkdirp "^0.5.1" + rimraf "^2.5.2" + sax@^1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" @@ -3632,6 +3669,13 @@ through@^2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" +tiny-glob@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/tiny-glob/-/tiny-glob-0.2.0.tgz#44d2feb1293308ed97520b9931d17c36432c7555" + dependencies: + globalyzer "^0.1.0" + globrex "0.0.2" + tippex@^2.1.1: version "2.3.1" resolved "https://registry.yarnpkg.com/tippex/-/tippex-2.3.1.tgz#a2fd5b7087d7cbfb20c9806a6c16108c2c0fafda"