From b381aa63a4103ce57bbaa563f3cf5f4926b928bd Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 29 Apr 2018 20:25:12 -0400 Subject: [PATCH 1/7] integrate CLI - fixes #1360 --- cli/compile.js | 220 +++++++ cli/index.js | 558 ++++++++++++++++++ package.json | 5 +- rollup.config.js | 20 + src/cli/compile.js | 139 +++++ src/cli/error.js | 17 + src/cli/index.js | 29 + svelte | 2 + test/cli/index.js | 76 +++ test/cli/samples/basic/actual/Main.js | 173 ++++++ test/cli/samples/basic/command.sh | 1 + test/cli/samples/basic/expected/Main.js | 173 ++++++ test/cli/samples/basic/src/Main.html | 1 + .../cli/samples/custom-element/actual/Main.js | 198 +++++++ test/cli/samples/custom-element/command.sh | 1 + .../samples/custom-element/expected/Main.js | 198 +++++++ test/cli/samples/custom-element/src/Main.html | 7 + test/cli/samples/dev/actual/Main.js | 197 +++++++ test/cli/samples/dev/command.sh | 1 + test/cli/samples/dev/expected/Main.js | 197 +++++++ test/cli/samples/dev/src/Main.html | 1 + test/cli/samples/dir-sourcemap/actual/Main.js | 181 ++++++ .../samples/dir-sourcemap/actual/Main.js.map | 1 + .../samples/dir-sourcemap/actual/Widget.js | 174 ++++++ .../dir-sourcemap/actual/Widget.js.map | 1 + test/cli/samples/dir-sourcemap/command.sh | 1 + .../samples/dir-sourcemap/expected/Main.js | 181 ++++++ .../dir-sourcemap/expected/Main.js.map | 1 + .../samples/dir-sourcemap/expected/Widget.js | 174 ++++++ .../dir-sourcemap/expected/Widget.js.map | 1 + test/cli/samples/dir-sourcemap/src/Main.html | 11 + .../cli/samples/dir-sourcemap/src/Widget.html | 1 + test/cli/samples/dir-subdir/actual/Main.js | 180 ++++++ .../dir-subdir/actual/widget/Widget.js | 173 ++++++ test/cli/samples/dir-subdir/command.sh | 1 + test/cli/samples/dir-subdir/expected/Main.js | 180 ++++++ .../dir-subdir/expected/widget/Widget.js | 173 ++++++ test/cli/samples/dir-subdir/src/Main.html | 11 + .../samples/dir-subdir/src/widget/Widget.html | 1 + test/cli/samples/dir/actual/Main.js | 180 ++++++ test/cli/samples/dir/actual/Widget.js | 173 ++++++ test/cli/samples/dir/command.sh | 1 + test/cli/samples/dir/expected/Main.js | 180 ++++++ test/cli/samples/dir/expected/Widget.js | 173 ++++++ test/cli/samples/dir/src/Main.html | 11 + test/cli/samples/dir/src/Widget.html | 1 + test/cli/samples/globals/actual/Main.js | 197 +++++++ test/cli/samples/globals/command.sh | 1 + test/cli/samples/globals/expected/Main.js | 197 +++++++ test/cli/samples/globals/src/Main.html | 13 + .../samples/sourcemap-inline/actual/Main.js | 174 ++++++ test/cli/samples/sourcemap-inline/command.sh | 1 + .../samples/sourcemap-inline/expected/Main.js | 174 ++++++ .../samples/sourcemap-inline/src/Main.html | 9 + test/cli/samples/sourcemap/actual/Main.js | 174 ++++++ test/cli/samples/sourcemap/actual/Main.js.map | 1 + test/cli/samples/sourcemap/command.sh | 1 + test/cli/samples/sourcemap/expected/Main.js | 174 ++++++ .../samples/sourcemap/expected/Main.js.map | 1 + test/cli/samples/sourcemap/src/Main.html | 9 + test/cli/samples/ssr/actual/Main.js | 48 ++ test/cli/samples/ssr/command.sh | 1 + test/cli/samples/ssr/expected/Main.js | 48 ++ test/cli/samples/ssr/src/Main.html | 1 + test/cli/samples/store/actual/Main.js | 195 ++++++ test/cli/samples/store/command.sh | 1 + test/cli/samples/store/expected/Main.js | 195 ++++++ test/cli/samples/store/src/Main.html | 1 + test/cli/update.js | 10 + test/helpers.js | 4 +- test/js/update.js | 4 +- test/parser/update.js | 4 +- test/server-side-rendering/index.js | 4 +- test/test.js | 6 +- yarn.lock | 50 +- 75 files changed, 6062 insertions(+), 15 deletions(-) create mode 100644 cli/compile.js create mode 100644 cli/index.js create mode 100644 src/cli/compile.js create mode 100644 src/cli/error.js create mode 100644 src/cli/index.js create mode 100755 svelte create mode 100644 test/cli/index.js create mode 100644 test/cli/samples/basic/actual/Main.js create mode 100644 test/cli/samples/basic/command.sh create mode 100644 test/cli/samples/basic/expected/Main.js create mode 100644 test/cli/samples/basic/src/Main.html create mode 100644 test/cli/samples/custom-element/actual/Main.js create mode 100644 test/cli/samples/custom-element/command.sh create mode 100644 test/cli/samples/custom-element/expected/Main.js create mode 100644 test/cli/samples/custom-element/src/Main.html create mode 100644 test/cli/samples/dev/actual/Main.js create mode 100644 test/cli/samples/dev/command.sh create mode 100644 test/cli/samples/dev/expected/Main.js create mode 100644 test/cli/samples/dev/src/Main.html create mode 100644 test/cli/samples/dir-sourcemap/actual/Main.js create mode 100644 test/cli/samples/dir-sourcemap/actual/Main.js.map create mode 100644 test/cli/samples/dir-sourcemap/actual/Widget.js create mode 100644 test/cli/samples/dir-sourcemap/actual/Widget.js.map create mode 100644 test/cli/samples/dir-sourcemap/command.sh create mode 100644 test/cli/samples/dir-sourcemap/expected/Main.js create mode 100644 test/cli/samples/dir-sourcemap/expected/Main.js.map create mode 100644 test/cli/samples/dir-sourcemap/expected/Widget.js create mode 100644 test/cli/samples/dir-sourcemap/expected/Widget.js.map create mode 100644 test/cli/samples/dir-sourcemap/src/Main.html create mode 100644 test/cli/samples/dir-sourcemap/src/Widget.html create mode 100644 test/cli/samples/dir-subdir/actual/Main.js create mode 100644 test/cli/samples/dir-subdir/actual/widget/Widget.js create mode 100644 test/cli/samples/dir-subdir/command.sh create mode 100644 test/cli/samples/dir-subdir/expected/Main.js create mode 100644 test/cli/samples/dir-subdir/expected/widget/Widget.js create mode 100644 test/cli/samples/dir-subdir/src/Main.html create mode 100644 test/cli/samples/dir-subdir/src/widget/Widget.html create mode 100644 test/cli/samples/dir/actual/Main.js create mode 100644 test/cli/samples/dir/actual/Widget.js create mode 100644 test/cli/samples/dir/command.sh create mode 100644 test/cli/samples/dir/expected/Main.js create mode 100644 test/cli/samples/dir/expected/Widget.js create mode 100644 test/cli/samples/dir/src/Main.html create mode 100644 test/cli/samples/dir/src/Widget.html create mode 100644 test/cli/samples/globals/actual/Main.js create mode 100644 test/cli/samples/globals/command.sh create mode 100644 test/cli/samples/globals/expected/Main.js create mode 100644 test/cli/samples/globals/src/Main.html create mode 100644 test/cli/samples/sourcemap-inline/actual/Main.js create mode 100644 test/cli/samples/sourcemap-inline/command.sh create mode 100644 test/cli/samples/sourcemap-inline/expected/Main.js create mode 100644 test/cli/samples/sourcemap-inline/src/Main.html create mode 100644 test/cli/samples/sourcemap/actual/Main.js create mode 100644 test/cli/samples/sourcemap/actual/Main.js.map create mode 100644 test/cli/samples/sourcemap/command.sh create mode 100644 test/cli/samples/sourcemap/expected/Main.js create mode 100644 test/cli/samples/sourcemap/expected/Main.js.map create mode 100644 test/cli/samples/sourcemap/src/Main.html create mode 100644 test/cli/samples/ssr/actual/Main.js create mode 100644 test/cli/samples/ssr/command.sh create mode 100644 test/cli/samples/ssr/expected/Main.js create mode 100644 test/cli/samples/ssr/src/Main.html create mode 100644 test/cli/samples/store/actual/Main.js create mode 100644 test/cli/samples/store/command.sh create mode 100644 test/cli/samples/store/expected/Main.js create mode 100644 test/cli/samples/store/src/Main.html create mode 100644 test/cli/update.js diff --git a/cli/compile.js b/cli/compile.js new file mode 100644 index 0000000000..6c76aea5a5 --- /dev/null +++ b/cli/compile.js @@ -0,0 +1,220 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var path = require('path'); +var fs = require('fs'); +var svelte = require('../compiler/svelte.js'); + +var ansi = (strip => ({ + reset: strip(["\x1b[0m"]), + newLine: ["\n", ""], + tab: ["\t", ""], + + black: strip(["\x1b[30m", "\x1b[39m"]), + red: strip(["\x1b[31m", "\x1b[39m"]), + green: strip(["\x1b[32m", "\x1b[39m"]), + yellow: strip(["\x1b[33m", "\x1b[39m"]), + blue: strip(["\x1b[34m", "\x1b[39m"]), + magenta: strip(["\x1b[35m", "\x1b[39m"]), + cyan: strip(["\x1b[36m", "\x1b[39m"]), + white: strip(["\x1b[37m", "\x1b[39m"]), + gray: strip(["\x1B[90m", "\x1b[39m"]), + + bgBlack: strip(["\x1b[40m", "\x1b[49m"]), + bgRed: strip(["\x1b[41m", "\x1b[49m"]), + bgGreen: strip(["\x1b[42m", "\x1b[49m"]), + bgYellow: strip(["\x1b[43m", "\x1b[49m"]), + bgBlue: strip(["\x1b[44m", "\x1b[49m"]), + bgMagenta: strip(["\x1b[45m", "\x1b[49m"]), + bgCyan: strip(["\x1b[46m", "\x1b[49m"]), + bgWhite: strip(["\x1b[47m", "\x1b[49m"]), + + dim: strip(["\x1b[2m", "\x1b[22m"]), + bold: strip(["\x1b[1m", "\x1b[22m"]), + hidden: strip(["\x1b[8m", "\x1b[28m"]), + italic: strip(["\x1b[3m", "\x1b[23m"]), + underline: strip(["\x1b[4m", "\x1b[24m"]), + inverse: strip(["\x1b[7m", "\x1b[27m"]), + strikethrough: strip(["\x1b[9m", "\x1b[29m"]) +}))( + ansi => + process.env.FORCE_COLOR || + process.platform === "win32" || + (process.stdout.isTTY && process.env.TERM && process.env.TERM !== "dumb") + ? ansi + : ["", ""] +); + +var ansi$1 = /*#__PURE__*/Object.freeze({ + default: ansi, + __moduleExports: ansi +}); + +var ansi$2 = ( ansi$1 && ansi ) || ansi$1; + +var clorox = (function Clorox(old, close) { + const clorox = s => Clorox(clorox.toString(s)); + + clorox.toString = s => old + (s || "") + (close || ansi$2.reset[0]); + + Object.keys(ansi$2).map(name => { + Object.defineProperty(clorox, name, { + get: () => Clorox(old + ansi$2[name][0], (close || "") + ansi$2[name][1]) + }); + }); + + return clorox +})(""); + +function stderr(msg) { + console.error(msg); // eslint-disable-line no-console +} + +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); +} + +function mkdirp(dir) { + const parent = path.dirname(dir); + if (dir === parent) return; + + mkdirp(parent); + if (!fs.existsSync(dir)) fs.mkdirSync(dir); +} + +async 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'); +} + +exports.compile = compile; diff --git a/cli/index.js b/cli/index.js new file mode 100644 index 0000000000..99e67320b4 --- /dev/null +++ b/cli/index.js @@ -0,0 +1,558 @@ +'use strict'; + +const EQQ = /\s|=/; +const FLAG = /^-{1,2}/; +const PREFIX = /^--no-/i; + +function isBool(any) { + return typeof any === 'boolean'; +} + +function toArr(any) { + return Array.isArray(any) ? any : any == null ? [] : [any]; +} + +function toString(any) { + return any == null || any === true ? '' : String(any); +} + +function toBool(any) { + return any === 'false' ? false : Boolean(any); +} + +function toNum(any) { + return (!isBool(any) && Number(any)) || any; +} + +function getAlibi(names, arr) { + if (arr.length === 0) return arr; + let k, i = 0, len = arr.length, vals = []; + for (; i < len; i++) { + k = arr[i]; + vals.push(k); + if (names[k] !== void 0) { + vals = vals.concat(names[k]); + } + } + return vals; +} + +function typecast(key, val, strings, booleans) { + if (strings.indexOf(key) !== -1) return toString(val); + if (booleans.indexOf(key) !== -1) return toBool(val); + return toNum(val); +} + +var lib = function(args, opts) { + args = args || []; + opts = opts || {}; + + opts.string = toArr(opts.string); + opts.boolean = toArr(opts.boolean); + + const aliases = {}; + let k, i, j, x, y, len, type; + + if (opts.alias !== void 0) { + for (k in opts.alias) { + aliases[k] = toArr(opts.alias[k]); + len = aliases[k].length; // save length + for (i = 0; i < len; i++) { + x = aliases[k][i]; // alias's key name + aliases[x] = [k]; // set initial array + for (j = 0; j < len; j++) { + if (x !== aliases[k][j]) { + aliases[x].push(aliases[k][j]); + } + } + } + } + } + + if (opts.default !== void 0) { + for (k in opts.default) { + type = typeof opts.default[k]; + opts[type] = (opts[type] || []).concat(k); + } + } + + // apply to all aliases + opts.string = getAlibi(aliases, opts.string); + opts.boolean = getAlibi(aliases, opts.boolean); + + let idx = 0; + const out = { _: [] }; + + while (args[idx] !== void 0) { + let incr = 1; + const val = args[idx]; + + if (val === '--') { + out._ = out._.concat(args.slice(idx + 1)); + break; + } else if (!FLAG.test(val)) { + out._.push(val); + } else if (PREFIX.test(val)) { + out[val.replace(PREFIX, '')] = false; + } else { + let tmp; + const segs = val.split(EQQ); + const isGroup = segs[0].charCodeAt(1) !== 45; // '-' + + const flag = segs[0].substr(isGroup ? 1 : 2); + len = flag.length; + const key = isGroup ? flag[len - 1] : flag; + + if (opts.unknown !== void 0 && aliases[key] === void 0) { + return opts.unknown(segs[0]); + } + + if (segs.length > 1) { + tmp = segs[1]; + } else { + tmp = args[idx + 1] || true; + FLAG.test(tmp) ? (tmp = true) : (incr = 2); + } + + if (isGroup && len > 1) { + for (i = len - 1; i--; ) { + k = flag[i]; // all but last key + out[k] = typecast(k, true, opts.string, opts.boolean); + } + } + + const value = typecast(key, tmp, opts.string, opts.boolean); + out[key] = out[key] !== void 0 ? toArr(out[key]).concat(value) : value; + + // handle discarded args when dealing with booleans + if (isBool(value) && !isBool(tmp) && tmp !== 'true' && tmp !== 'false') { + out._.push(tmp); + } + } + + idx += incr; + } + + if (opts.default !== void 0) { + for (k in opts.default) { + if (out[k] === void 0) { + out[k] = opts.default[k]; + } + } + } + + for (k in out) { + if (aliases[k] === void 0) continue; + y = out[k]; + len = aliases[k].length; + for (i = 0; i < len; i++) { + out[aliases[k][i]] = y; // assign value + } + } + + return out; +}; + +var lib$1 = /*#__PURE__*/Object.freeze({ + default: lib, + __moduleExports: lib +}); + +/*! + * repeat-string + * + * Copyright (c) 2014-2015, Jon Schlinkert. + * Licensed under the MIT License. + */ + +/** + * Results cache + */ + +var res = ''; +var cache; + +/** + * Expose `repeat` + */ + +var repeatString = repeat; + +/** + * Repeat the given `string` the specified `number` + * of times. + * + * **Example:** + * + * ```js + * var repeat = require('repeat-string'); + * repeat('A', 5); + * //=> AAAAA + * ``` + * + * @param {String} `string` The string to repeat + * @param {Number} `number` The number of times to repeat the string + * @return {String} Repeated string + * @api public + */ + +function repeat(str, num) { + if (typeof str !== 'string') { + throw new TypeError('expected a string'); + } + + // cover common, quick use cases + if (num === 1) return str; + if (num === 2) return str + str; + + var max = str.length * num; + if (cache !== str || typeof cache === 'undefined') { + cache = str; + res = ''; + } else if (res.length >= max) { + return res.substr(0, max); + } + + while (max > res.length && num > 1) { + if (num & 1) { + res += str; + } + + num >>= 1; + str += str; + } + + res += str; + res = res.substr(0, max); + return res; +} + +var repeatString$1 = /*#__PURE__*/Object.freeze({ + default: repeatString, + __moduleExports: repeatString +}); + +var repeat$1 = ( repeatString$1 && repeatString ) || repeatString$1; + +var padRight = function padLeft(val, num, str) { + var padding = ''; + var diff = num - val.length; + + // Breakpoints based on benchmarks to use the fastest approach + // for the given number of zeros + if (diff <= 5 && !str) { + padding = '00000'; + } else if (diff <= 25 && !str) { + padding = '000000000000000000000000000'; + } else { + return val + repeat$1(str || '0', diff); + } + + return val + padding.slice(0, diff); +}; + +var padRight$1 = /*#__PURE__*/Object.freeze({ + default: padRight, + __moduleExports: padRight +}); + +var rpad = ( padRight$1 && padRight ) || padRight$1; + +const GAP = 4; +const __ = ' '; +const ALL = '__all__'; +const DEF = '__default__'; +const NL = '\n'; + +function format(arr) { + if (!arr.length) return ''; + let len = maxLen( arr.map(x => x[0]) ) + GAP; + let join = a => rpad(a[0], len, ' ') + a[1] + (a[2] == null ? '' : ` (default ${a[2]})`); + return arr.map(join); +} + +function maxLen(arr) { + let c=0, d=0, l=0, i=arr.length; + if (i) while (i--) { + d = arr[i].length; + if (d > c) { + l = i; c = d; + } + } + return arr[l].length; +} + +function noop(s) { + return s; +} + +function section(str, arr, fn) { + if (!arr || !arr.length) return ''; + let i=0, out=''; + out += (NL + __ + str); + for (; i < arr.length; i++) { + out += (NL + __ + __ + fn(arr[i])); + } + return out + NL; +} + +var help = function (bin, tree, key) { + let out='', cmd=tree[key], pfx=`$ ${bin}`, all=tree[ALL]; + let prefix = s => `${pfx} ${s}`; + + // update ALL & CMD options + all.options.push(['-h, --help', 'Displays this message']); + cmd.options = (cmd.options || []).concat(all.options); + + // write options placeholder + (cmd.options.length > 0) && (cmd.usage += ' [options]'); + + // description ~> text only; usage ~> prefixed + out += section('Description', cmd.describe, noop); + out += section('Usage', [cmd.usage], prefix); + + if (key === DEF) { + // General help :: print all non-internal commands & their 1st line of text + let cmds = Object.keys(tree).filter(k => !/__/.test(k)); + let text = cmds.map(k => [k, (tree[k].describe || [''])[0]]); + out += section('Available Commands', format(text), noop); + + out += (NL + __ + 'For more info, run any command with the `--help` flag'); + cmds.slice(0, 2).forEach(k => { + out += (NL + __ + __ + `${pfx} ${k} --help`); + }); + out += NL; + } + + out += section('Options', format(cmd.options), noop); + out += section('Examples', cmd.examples.map(prefix), noop); + + return out; +}; + +var error = function (bin, str, num=1) { + let out = section('ERROR', [str], noop); + out += (NL + __ + `Run \`$ ${bin} --help\` for more info.` + NL); + console.error(out); + process.exit(num); +}; + +// Strips leading `-|--` & extra space(s) +var parse = function (str) { + return (str || '').split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean); +}; + +// @see https://stackoverflow.com/a/18914855/3577474 +var sentences = function (str) { + return (str || '').replace(/([.?!])\s*(?=[A-Z])/g, '$1|').split('|'); +}; + +var utils = { + help: help, + error: error, + parse: parse, + sentences: sentences +}; + +var utils$1 = /*#__PURE__*/Object.freeze({ + default: utils, + __moduleExports: utils, + help: help, + error: error, + parse: parse, + sentences: sentences +}); + +var mri = ( lib$1 && lib ) || lib$1; + +var $ = ( utils$1 && utils ) || utils$1; + +const ALL$1 = '__all__'; +const DEF$1 = '__default__'; + +class Sade { + constructor(name) { + this.tree = {}; + this.name = name; + this.ver = '0.0.0'; + this.default = ''; + // set internal shapes; + this.command(ALL$1); + this.command(`${DEF$1} `) + .option('-v, --version', 'Displays current version'); + this.curr = ''; // reset + } + + command(str, desc, opts) { + let cmd=[], usage=[], rgx=/(\[|<)/; + // All non-([|<) are commands + str.split(/\s+/).forEach(x => { + (rgx.test(x.charAt(0)) ? usage : cmd).push(x); + }); + + // Back to string~! + cmd = cmd.join(' '); + + if (cmd in this.tree) { + throw new Error(`Command already exists: ${cmd}`); + } + + this.curr = cmd; + (opts && opts.default) && (this.default=cmd); + + !~cmd.indexOf('__') && usage.unshift(cmd); // re-include `cmd` + usage = usage.join(' '); // to string + + this.tree[cmd] = { usage, options:[], alias:{}, default:{}, examples:[] }; + desc && this.describe(desc); + + return this; + } + + describe(str) { + this.tree[this.curr || DEF$1].describe = Array.isArray(str) ? str : $.sentences(str); + return this; + } + + option(str, desc, val) { + let cmd = this.tree[ this.curr || ALL$1 ]; + + let [flag, alias] = $.parse(str); + (alias && alias.length > 1) && ([flag, alias]=[alias, flag]); + + str = `--${flag}`; + if (alias && alias.length > 0) { + str = `-${alias}, ${str}`; + let old = cmd.alias[alias]; + cmd.alias[alias] = (old || []).concat(flag); + } + + let arr = [str, desc || '']; + + if (val !== void 0) { + arr.push(val); + cmd.default[flag] = val; + } + + cmd.options.push(arr); + return this; + } + + action(handler) { + this.tree[ this.curr || DEF$1 ].handler = handler; + return this; + } + + example(str) { + this.tree[ this.curr || DEF$1 ].examples.push(str); + return this; + } + + version(str) { + this.ver = str; + return this; + } + + parse(arr, opts={}) { + let offset = 2; // argv slicer + let alias = { h:'help', v:'version' }; + let argv = mri(arr.slice(offset), { alias }); + let bin = this.name; + + // Loop thru possible command(s) + let tmp, name=''; + let i=1, len=argv._.length + 1; + for (; i < len; i++) { + tmp = argv._.slice(0, i).join(' '); + if (this.tree[tmp] !== void 0) { + name=tmp; offset=(i + 2); // argv slicer + } + } + + let cmd = this.tree[name]; + let isVoid = (cmd === void 0); + + if (isVoid) { + if (this.default) { + name = this.default; + cmd = this.tree[name]; + arr.unshift(name); + offset++; + } else if (name) { + return $.error(bin, `Invalid command: ${name}`); + } //=> else: cmd not specified, wait for now... + } + + if (argv.version) { + return console.log(`${bin}, ${this.ver}`); + } + + if (argv.help) { + return this.help(!isVoid && name); + } + + if (cmd === void 0) { + return $.error(bin, 'No command specified.'); + } + + let all = this.tree[ALL$1]; + // merge all objects :: params > command > all + opts.alias = Object.assign(all.alias, cmd.alias, opts.alias); + opts.default = Object.assign(all.default, cmd.default, opts.default); + + let vals = mri(arr.slice(offset), opts); + let segs = cmd.usage.split(/\s+/); + let reqs = segs.filter(x => x.charAt(0)==='<'); + let args = vals._.splice(0, reqs.length); + + if (args.length < reqs.length) { + name && (bin += ` ${name}`); // for help text + return $.error(bin, 'Insufficient arguments!'); + } + + segs.filter(x => x.charAt(0)==='[').forEach(_ => { + args.push(vals._.pop()); // adds `undefined` per [slot] if no more + }); + + args.push(vals); // flags & co are last + let handler = cmd.handler; + return opts.lazy ? { args, name, handler } : handler.apply(null, args); + } + + help(str) { + console.log( + $.help(this.name, this.tree, str || DEF$1) + ); + } +} + +var lib$2 = str => new Sade(str); + +var version = "2.3.0"; + +const prog = lib$2('svelte-cli').version(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(async (input, opts) => { + const { compile } = await Promise.resolve(require("./compile.js")); + compile(input, opts); + }) + + .parse(process.argv); diff --git a/package.json b/package.json index 651cda4a81..712b1eaf0d 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,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 +56,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 +75,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..bce82c334f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -57,6 +57,26 @@ export default [ } }, + /* cli/*.js */ + { + input: ['src/cli/index.js'], + output: { + dir: 'cli', + format: 'cjs' + }, + external: ['fs', 'path', 'os', 'svelte'], + paths: { + svelte: '../compiler/svelte.js' + }, + plugins: [ + json(), + commonjs(), + resolve() + ], + experimentalDynamicImport: true, + experimentalCodeSplitting: true + }, + /* shared.js */ { input: 'src/shared/index.js', diff --git a/src/cli/compile.js b/src/cli/compile.js new file mode 100644 index 0000000000..b22d489ea4 --- /dev/null +++ b/src/cli/compile.js @@ -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 async 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.js b/src/cli/error.js new file mode 100644 index 0000000000..b7ca813716 --- /dev/null +++ b/src/cli/error.js @@ -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.js b/src/cli/index.js new file mode 100644 index 0000000000..52137a6657 --- /dev/null +++ b/src/cli/index.js @@ -0,0 +1,29 @@ +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(async (input, opts) => { + const { compile } = await import('./compile.js'); + compile(input, opts); + }) + + .parse(process.argv); \ No newline at end of file diff --git a/svelte b/svelte new file mode 100755 index 0000000000..0297932340 --- /dev/null +++ b/svelte @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('./cli/index.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..5bd623c0f1 --- /dev/null +++ b/test/cli/index.js @@ -0,0 +1,76 @@ +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, '').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') + ) + }; + }); + + 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/actual/Main.js b/test/cli/samples/basic/actual/Main.js new file mode 100644 index 0000000000..c9e83d1bcb --- /dev/null +++ b/test/cli/samples/basic/actual/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: 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) { + 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/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..c9e83d1bcb --- /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: 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) { + 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/actual/Main.js b/test/cli/samples/custom-element/actual/Main.js new file mode 100644 index 0000000000..b14170bb99 --- /dev/null +++ b/test/cli/samples/custom-element/actual/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: function create() { + p = createElement("p"); + p.textContent = "Hello world!"; + this.c = noop; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/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..b14170bb99 --- /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: function create() { + p = createElement("p"); + p.textContent = "Hello world!"; + this.c = noop; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/actual/Main.js b/test/cli/samples/dev/actual/Main.js new file mode 100644 index 0000000000..401307fe2e --- /dev/null +++ b/test/cli/samples/dev/actual/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/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/actual/Main.js b/test/cli/samples/dir-sourcemap/actual/Main.js new file mode 100644 index 0000000000..755b86eb22 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/actual/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: function create() { + widget._fragment.c(); + }, + + m: function mount(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + widget._unmount(); + }, + + d: function destroy() { + 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/actual/Main.js.map b/test/cli/samples/dir-sourcemap/actual/Main.js.map new file mode 100644 index 0000000000..cf890d4435 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/actual/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/actual/Widget.js b/test/cli/samples/dir-sourcemap/actual/Widget.js new file mode 100644 index 0000000000..74e2b61f2a --- /dev/null +++ b/test/cli/samples/dir-sourcemap/actual/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: function create() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/actual/Widget.js.map b/test/cli/samples/dir-sourcemap/actual/Widget.js.map new file mode 100644 index 0000000000..d007680a81 --- /dev/null +++ b/test/cli/samples/dir-sourcemap/actual/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/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..755b86eb22 --- /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: function create() { + widget._fragment.c(); + }, + + m: function mount(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + widget._unmount(); + }, + + d: function destroy() { + 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..74e2b61f2a --- /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: function create() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/actual/Main.js b/test/cli/samples/dir-subdir/actual/Main.js new file mode 100644 index 0000000000..e2f801836d --- /dev/null +++ b/test/cli/samples/dir-subdir/actual/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: function create() { + widget._fragment.c(); + }, + + m: function mount(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + widget._unmount(); + }, + + d: function destroy() { + 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/actual/widget/Widget.js b/test/cli/samples/dir-subdir/actual/widget/Widget.js new file mode 100644 index 0000000000..8dba93394a --- /dev/null +++ b/test/cli/samples/dir-subdir/actual/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: function create() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/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..e2f801836d --- /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: function create() { + widget._fragment.c(); + }, + + m: function mount(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + widget._unmount(); + }, + + d: function destroy() { + 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..8dba93394a --- /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: function create() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/actual/Main.js b/test/cli/samples/dir/actual/Main.js new file mode 100644 index 0000000000..046670e333 --- /dev/null +++ b/test/cli/samples/dir/actual/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: function create() { + widget._fragment.c(); + }, + + m: function mount(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + widget._unmount(); + }, + + d: function destroy() { + 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/actual/Widget.js b/test/cli/samples/dir/actual/Widget.js new file mode 100644 index 0000000000..10c9542744 --- /dev/null +++ b/test/cli/samples/dir/actual/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: function create() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/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..046670e333 --- /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: function create() { + widget._fragment.c(); + }, + + m: function mount(target, anchor) { + widget._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + widget._unmount(); + }, + + d: function destroy() { + 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..10c9542744 --- /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: function create() { + p = createElement("p"); + p.textContent = "widget"; + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + }, + + p: noop, + + u: function unmount() { + 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/actual/Main.js b/test/cli/samples/globals/actual/Main.js new file mode 100644 index 0000000000..829c294a1a --- /dev/null +++ b/test/cli/samples/globals/actual/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: function create() { + p = createElement("p"); + text = createText("The answer is "); + text_1 = createText(ctx.answer); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + }, + + p: function update(changed, ctx) { + if (changed.answer) { + text_1.data = ctx.answer; + } + }, + + u: function unmount() { + 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/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..829c294a1a --- /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: function create() { + p = createElement("p"); + text = createText("The answer is "); + text_1 = createText(ctx.answer); + }, + + m: function mount(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + appendNode(text_1, p); + }, + + p: function update(changed, ctx) { + if (changed.answer) { + text_1.data = ctx.answer; + } + }, + + u: function unmount() { + 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/actual/Main.js b/test/cli/samples/sourcemap-inline/actual/Main.js new file mode 100644 index 0000000000..4e95c96c37 --- /dev/null +++ b/test/cli/samples/sourcemap-inline/actual/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: 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) { + 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/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..4e95c96c37 --- /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: 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) { + 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/actual/Main.js b/test/cli/samples/sourcemap/actual/Main.js new file mode 100644 index 0000000000..2a532f70b1 --- /dev/null +++ b/test/cli/samples/sourcemap/actual/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: 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) { + 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/actual/Main.js.map b/test/cli/samples/sourcemap/actual/Main.js.map new file mode 100644 index 0000000000..5133d81436 --- /dev/null +++ b/test/cli/samples/sourcemap/actual/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/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..2a532f70b1 --- /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: 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) { + 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/actual/Main.js b/test/cli/samples/ssr/actual/Main.js new file mode 100644 index 0000000000..adf4e19fa0 --- /dev/null +++ b/test/cli/samples/ssr/actual/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/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/actual/Main.js b/test/cli/samples/store/actual/Main.js new file mode 100644 index 0000000000..228491d77a --- /dev/null +++ b/test/cli/samples/store/actual/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: function create() { + h1 = createElement("h1"); + text = createText("Hello "); + text_1 = createText(ctx.$name); + }, + + m: function mount(target, anchor) { + insertNode(h1, target, anchor); + appendNode(text, h1); + appendNode(text_1, h1); + }, + + p: function update(changed, ctx) { + if (changed.$name) { + text_1.data = ctx.$name; + } + }, + + u: function unmount() { + 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/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..228491d77a --- /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: function create() { + h1 = createElement("h1"); + text = createText("Hello "); + text_1 = createText(ctx.$name); + }, + + m: function mount(target, anchor) { + insertNode(h1, target, anchor); + appendNode(text, h1); + appendNode(text_1, h1); + }, + + p: function update(changed, ctx) { + if (changed.$name) { + text_1.data = ctx.$name; + } + }, + + u: function unmount() { + 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" From 7af7945d174967638c2115775cd4c7e4181afeb5 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 29 Apr 2018 20:27:18 -0400 Subject: [PATCH 2/7] update gitignore and pkg.files --- .gitignore | 1 + cli/compile.js | 220 ------------------- cli/index.js | 558 ------------------------------------------------- package.json | 2 + 4 files changed, 3 insertions(+), 778 deletions(-) delete mode 100644 cli/compile.js delete mode 100644 cli/index.js diff --git a/.gitignore b/.gitignore index ed21efb721..b58299e656 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store .nyc_output node_modules +/cli/ /compiler/ /ssr/ /shared.js diff --git a/cli/compile.js b/cli/compile.js deleted file mode 100644 index 6c76aea5a5..0000000000 --- a/cli/compile.js +++ /dev/null @@ -1,220 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -var path = require('path'); -var fs = require('fs'); -var svelte = require('../compiler/svelte.js'); - -var ansi = (strip => ({ - reset: strip(["\x1b[0m"]), - newLine: ["\n", ""], - tab: ["\t", ""], - - black: strip(["\x1b[30m", "\x1b[39m"]), - red: strip(["\x1b[31m", "\x1b[39m"]), - green: strip(["\x1b[32m", "\x1b[39m"]), - yellow: strip(["\x1b[33m", "\x1b[39m"]), - blue: strip(["\x1b[34m", "\x1b[39m"]), - magenta: strip(["\x1b[35m", "\x1b[39m"]), - cyan: strip(["\x1b[36m", "\x1b[39m"]), - white: strip(["\x1b[37m", "\x1b[39m"]), - gray: strip(["\x1B[90m", "\x1b[39m"]), - - bgBlack: strip(["\x1b[40m", "\x1b[49m"]), - bgRed: strip(["\x1b[41m", "\x1b[49m"]), - bgGreen: strip(["\x1b[42m", "\x1b[49m"]), - bgYellow: strip(["\x1b[43m", "\x1b[49m"]), - bgBlue: strip(["\x1b[44m", "\x1b[49m"]), - bgMagenta: strip(["\x1b[45m", "\x1b[49m"]), - bgCyan: strip(["\x1b[46m", "\x1b[49m"]), - bgWhite: strip(["\x1b[47m", "\x1b[49m"]), - - dim: strip(["\x1b[2m", "\x1b[22m"]), - bold: strip(["\x1b[1m", "\x1b[22m"]), - hidden: strip(["\x1b[8m", "\x1b[28m"]), - italic: strip(["\x1b[3m", "\x1b[23m"]), - underline: strip(["\x1b[4m", "\x1b[24m"]), - inverse: strip(["\x1b[7m", "\x1b[27m"]), - strikethrough: strip(["\x1b[9m", "\x1b[29m"]) -}))( - ansi => - process.env.FORCE_COLOR || - process.platform === "win32" || - (process.stdout.isTTY && process.env.TERM && process.env.TERM !== "dumb") - ? ansi - : ["", ""] -); - -var ansi$1 = /*#__PURE__*/Object.freeze({ - default: ansi, - __moduleExports: ansi -}); - -var ansi$2 = ( ansi$1 && ansi ) || ansi$1; - -var clorox = (function Clorox(old, close) { - const clorox = s => Clorox(clorox.toString(s)); - - clorox.toString = s => old + (s || "") + (close || ansi$2.reset[0]); - - Object.keys(ansi$2).map(name => { - Object.defineProperty(clorox, name, { - get: () => Clorox(old + ansi$2[name][0], (close || "") + ansi$2[name][1]) - }); - }); - - return clorox -})(""); - -function stderr(msg) { - console.error(msg); // eslint-disable-line no-console -} - -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); -} - -function mkdirp(dir) { - const parent = path.dirname(dir); - if (dir === parent) return; - - mkdirp(parent); - if (!fs.existsSync(dir)) fs.mkdirSync(dir); -} - -async 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'); -} - -exports.compile = compile; diff --git a/cli/index.js b/cli/index.js deleted file mode 100644 index 99e67320b4..0000000000 --- a/cli/index.js +++ /dev/null @@ -1,558 +0,0 @@ -'use strict'; - -const EQQ = /\s|=/; -const FLAG = /^-{1,2}/; -const PREFIX = /^--no-/i; - -function isBool(any) { - return typeof any === 'boolean'; -} - -function toArr(any) { - return Array.isArray(any) ? any : any == null ? [] : [any]; -} - -function toString(any) { - return any == null || any === true ? '' : String(any); -} - -function toBool(any) { - return any === 'false' ? false : Boolean(any); -} - -function toNum(any) { - return (!isBool(any) && Number(any)) || any; -} - -function getAlibi(names, arr) { - if (arr.length === 0) return arr; - let k, i = 0, len = arr.length, vals = []; - for (; i < len; i++) { - k = arr[i]; - vals.push(k); - if (names[k] !== void 0) { - vals = vals.concat(names[k]); - } - } - return vals; -} - -function typecast(key, val, strings, booleans) { - if (strings.indexOf(key) !== -1) return toString(val); - if (booleans.indexOf(key) !== -1) return toBool(val); - return toNum(val); -} - -var lib = function(args, opts) { - args = args || []; - opts = opts || {}; - - opts.string = toArr(opts.string); - opts.boolean = toArr(opts.boolean); - - const aliases = {}; - let k, i, j, x, y, len, type; - - if (opts.alias !== void 0) { - for (k in opts.alias) { - aliases[k] = toArr(opts.alias[k]); - len = aliases[k].length; // save length - for (i = 0; i < len; i++) { - x = aliases[k][i]; // alias's key name - aliases[x] = [k]; // set initial array - for (j = 0; j < len; j++) { - if (x !== aliases[k][j]) { - aliases[x].push(aliases[k][j]); - } - } - } - } - } - - if (opts.default !== void 0) { - for (k in opts.default) { - type = typeof opts.default[k]; - opts[type] = (opts[type] || []).concat(k); - } - } - - // apply to all aliases - opts.string = getAlibi(aliases, opts.string); - opts.boolean = getAlibi(aliases, opts.boolean); - - let idx = 0; - const out = { _: [] }; - - while (args[idx] !== void 0) { - let incr = 1; - const val = args[idx]; - - if (val === '--') { - out._ = out._.concat(args.slice(idx + 1)); - break; - } else if (!FLAG.test(val)) { - out._.push(val); - } else if (PREFIX.test(val)) { - out[val.replace(PREFIX, '')] = false; - } else { - let tmp; - const segs = val.split(EQQ); - const isGroup = segs[0].charCodeAt(1) !== 45; // '-' - - const flag = segs[0].substr(isGroup ? 1 : 2); - len = flag.length; - const key = isGroup ? flag[len - 1] : flag; - - if (opts.unknown !== void 0 && aliases[key] === void 0) { - return opts.unknown(segs[0]); - } - - if (segs.length > 1) { - tmp = segs[1]; - } else { - tmp = args[idx + 1] || true; - FLAG.test(tmp) ? (tmp = true) : (incr = 2); - } - - if (isGroup && len > 1) { - for (i = len - 1; i--; ) { - k = flag[i]; // all but last key - out[k] = typecast(k, true, opts.string, opts.boolean); - } - } - - const value = typecast(key, tmp, opts.string, opts.boolean); - out[key] = out[key] !== void 0 ? toArr(out[key]).concat(value) : value; - - // handle discarded args when dealing with booleans - if (isBool(value) && !isBool(tmp) && tmp !== 'true' && tmp !== 'false') { - out._.push(tmp); - } - } - - idx += incr; - } - - if (opts.default !== void 0) { - for (k in opts.default) { - if (out[k] === void 0) { - out[k] = opts.default[k]; - } - } - } - - for (k in out) { - if (aliases[k] === void 0) continue; - y = out[k]; - len = aliases[k].length; - for (i = 0; i < len; i++) { - out[aliases[k][i]] = y; // assign value - } - } - - return out; -}; - -var lib$1 = /*#__PURE__*/Object.freeze({ - default: lib, - __moduleExports: lib -}); - -/*! - * repeat-string - * - * Copyright (c) 2014-2015, Jon Schlinkert. - * Licensed under the MIT License. - */ - -/** - * Results cache - */ - -var res = ''; -var cache; - -/** - * Expose `repeat` - */ - -var repeatString = repeat; - -/** - * Repeat the given `string` the specified `number` - * of times. - * - * **Example:** - * - * ```js - * var repeat = require('repeat-string'); - * repeat('A', 5); - * //=> AAAAA - * ``` - * - * @param {String} `string` The string to repeat - * @param {Number} `number` The number of times to repeat the string - * @return {String} Repeated string - * @api public - */ - -function repeat(str, num) { - if (typeof str !== 'string') { - throw new TypeError('expected a string'); - } - - // cover common, quick use cases - if (num === 1) return str; - if (num === 2) return str + str; - - var max = str.length * num; - if (cache !== str || typeof cache === 'undefined') { - cache = str; - res = ''; - } else if (res.length >= max) { - return res.substr(0, max); - } - - while (max > res.length && num > 1) { - if (num & 1) { - res += str; - } - - num >>= 1; - str += str; - } - - res += str; - res = res.substr(0, max); - return res; -} - -var repeatString$1 = /*#__PURE__*/Object.freeze({ - default: repeatString, - __moduleExports: repeatString -}); - -var repeat$1 = ( repeatString$1 && repeatString ) || repeatString$1; - -var padRight = function padLeft(val, num, str) { - var padding = ''; - var diff = num - val.length; - - // Breakpoints based on benchmarks to use the fastest approach - // for the given number of zeros - if (diff <= 5 && !str) { - padding = '00000'; - } else if (diff <= 25 && !str) { - padding = '000000000000000000000000000'; - } else { - return val + repeat$1(str || '0', diff); - } - - return val + padding.slice(0, diff); -}; - -var padRight$1 = /*#__PURE__*/Object.freeze({ - default: padRight, - __moduleExports: padRight -}); - -var rpad = ( padRight$1 && padRight ) || padRight$1; - -const GAP = 4; -const __ = ' '; -const ALL = '__all__'; -const DEF = '__default__'; -const NL = '\n'; - -function format(arr) { - if (!arr.length) return ''; - let len = maxLen( arr.map(x => x[0]) ) + GAP; - let join = a => rpad(a[0], len, ' ') + a[1] + (a[2] == null ? '' : ` (default ${a[2]})`); - return arr.map(join); -} - -function maxLen(arr) { - let c=0, d=0, l=0, i=arr.length; - if (i) while (i--) { - d = arr[i].length; - if (d > c) { - l = i; c = d; - } - } - return arr[l].length; -} - -function noop(s) { - return s; -} - -function section(str, arr, fn) { - if (!arr || !arr.length) return ''; - let i=0, out=''; - out += (NL + __ + str); - for (; i < arr.length; i++) { - out += (NL + __ + __ + fn(arr[i])); - } - return out + NL; -} - -var help = function (bin, tree, key) { - let out='', cmd=tree[key], pfx=`$ ${bin}`, all=tree[ALL]; - let prefix = s => `${pfx} ${s}`; - - // update ALL & CMD options - all.options.push(['-h, --help', 'Displays this message']); - cmd.options = (cmd.options || []).concat(all.options); - - // write options placeholder - (cmd.options.length > 0) && (cmd.usage += ' [options]'); - - // description ~> text only; usage ~> prefixed - out += section('Description', cmd.describe, noop); - out += section('Usage', [cmd.usage], prefix); - - if (key === DEF) { - // General help :: print all non-internal commands & their 1st line of text - let cmds = Object.keys(tree).filter(k => !/__/.test(k)); - let text = cmds.map(k => [k, (tree[k].describe || [''])[0]]); - out += section('Available Commands', format(text), noop); - - out += (NL + __ + 'For more info, run any command with the `--help` flag'); - cmds.slice(0, 2).forEach(k => { - out += (NL + __ + __ + `${pfx} ${k} --help`); - }); - out += NL; - } - - out += section('Options', format(cmd.options), noop); - out += section('Examples', cmd.examples.map(prefix), noop); - - return out; -}; - -var error = function (bin, str, num=1) { - let out = section('ERROR', [str], noop); - out += (NL + __ + `Run \`$ ${bin} --help\` for more info.` + NL); - console.error(out); - process.exit(num); -}; - -// Strips leading `-|--` & extra space(s) -var parse = function (str) { - return (str || '').split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean); -}; - -// @see https://stackoverflow.com/a/18914855/3577474 -var sentences = function (str) { - return (str || '').replace(/([.?!])\s*(?=[A-Z])/g, '$1|').split('|'); -}; - -var utils = { - help: help, - error: error, - parse: parse, - sentences: sentences -}; - -var utils$1 = /*#__PURE__*/Object.freeze({ - default: utils, - __moduleExports: utils, - help: help, - error: error, - parse: parse, - sentences: sentences -}); - -var mri = ( lib$1 && lib ) || lib$1; - -var $ = ( utils$1 && utils ) || utils$1; - -const ALL$1 = '__all__'; -const DEF$1 = '__default__'; - -class Sade { - constructor(name) { - this.tree = {}; - this.name = name; - this.ver = '0.0.0'; - this.default = ''; - // set internal shapes; - this.command(ALL$1); - this.command(`${DEF$1} `) - .option('-v, --version', 'Displays current version'); - this.curr = ''; // reset - } - - command(str, desc, opts) { - let cmd=[], usage=[], rgx=/(\[|<)/; - // All non-([|<) are commands - str.split(/\s+/).forEach(x => { - (rgx.test(x.charAt(0)) ? usage : cmd).push(x); - }); - - // Back to string~! - cmd = cmd.join(' '); - - if (cmd in this.tree) { - throw new Error(`Command already exists: ${cmd}`); - } - - this.curr = cmd; - (opts && opts.default) && (this.default=cmd); - - !~cmd.indexOf('__') && usage.unshift(cmd); // re-include `cmd` - usage = usage.join(' '); // to string - - this.tree[cmd] = { usage, options:[], alias:{}, default:{}, examples:[] }; - desc && this.describe(desc); - - return this; - } - - describe(str) { - this.tree[this.curr || DEF$1].describe = Array.isArray(str) ? str : $.sentences(str); - return this; - } - - option(str, desc, val) { - let cmd = this.tree[ this.curr || ALL$1 ]; - - let [flag, alias] = $.parse(str); - (alias && alias.length > 1) && ([flag, alias]=[alias, flag]); - - str = `--${flag}`; - if (alias && alias.length > 0) { - str = `-${alias}, ${str}`; - let old = cmd.alias[alias]; - cmd.alias[alias] = (old || []).concat(flag); - } - - let arr = [str, desc || '']; - - if (val !== void 0) { - arr.push(val); - cmd.default[flag] = val; - } - - cmd.options.push(arr); - return this; - } - - action(handler) { - this.tree[ this.curr || DEF$1 ].handler = handler; - return this; - } - - example(str) { - this.tree[ this.curr || DEF$1 ].examples.push(str); - return this; - } - - version(str) { - this.ver = str; - return this; - } - - parse(arr, opts={}) { - let offset = 2; // argv slicer - let alias = { h:'help', v:'version' }; - let argv = mri(arr.slice(offset), { alias }); - let bin = this.name; - - // Loop thru possible command(s) - let tmp, name=''; - let i=1, len=argv._.length + 1; - for (; i < len; i++) { - tmp = argv._.slice(0, i).join(' '); - if (this.tree[tmp] !== void 0) { - name=tmp; offset=(i + 2); // argv slicer - } - } - - let cmd = this.tree[name]; - let isVoid = (cmd === void 0); - - if (isVoid) { - if (this.default) { - name = this.default; - cmd = this.tree[name]; - arr.unshift(name); - offset++; - } else if (name) { - return $.error(bin, `Invalid command: ${name}`); - } //=> else: cmd not specified, wait for now... - } - - if (argv.version) { - return console.log(`${bin}, ${this.ver}`); - } - - if (argv.help) { - return this.help(!isVoid && name); - } - - if (cmd === void 0) { - return $.error(bin, 'No command specified.'); - } - - let all = this.tree[ALL$1]; - // merge all objects :: params > command > all - opts.alias = Object.assign(all.alias, cmd.alias, opts.alias); - opts.default = Object.assign(all.default, cmd.default, opts.default); - - let vals = mri(arr.slice(offset), opts); - let segs = cmd.usage.split(/\s+/); - let reqs = segs.filter(x => x.charAt(0)==='<'); - let args = vals._.splice(0, reqs.length); - - if (args.length < reqs.length) { - name && (bin += ` ${name}`); // for help text - return $.error(bin, 'Insufficient arguments!'); - } - - segs.filter(x => x.charAt(0)==='[').forEach(_ => { - args.push(vals._.pop()); // adds `undefined` per [slot] if no more - }); - - args.push(vals); // flags & co are last - let handler = cmd.handler; - return opts.lazy ? { args, name, handler } : handler.apply(null, args); - } - - help(str) { - console.log( - $.help(this.name, this.tree, str || DEF$1) - ); - } -} - -var lib$2 = str => new Sade(str); - -var version = "2.3.0"; - -const prog = lib$2('svelte-cli').version(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(async (input, opts) => { - const { compile } = await Promise.resolve(require("./compile.js")); - compile(input, opts); - }) - - .parse(process.argv); diff --git a/package.json b/package.json index 712b1eaf0d..aa65922f4b 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,13 @@ "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", "files": [ + "cli", "compiler", "ssr", "shared.js", "store.js", "store.umd.js", + "svelte", "README.md" ], "scripts": { From 5c78794f1b5335620a4d97f17b6d5b2a702248f3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 29 Apr 2018 20:39:35 -0400 Subject: [PATCH 3/7] use TypeScript for CLI --- rollup.config.js | 7 +++++-- src/cli/{compile.js => compile.ts} | 0 src/cli/{error.js => error.ts} | 0 src/cli/{index.js => index.ts} | 0 svelte | 2 +- 5 files changed, 6 insertions(+), 3 deletions(-) rename src/cli/{compile.js => compile.ts} (100%) rename src/cli/{error.js => error.ts} (100%) rename src/cli/{index.js => index.ts} (100%) diff --git a/rollup.config.js b/rollup.config.js index bce82c334f..59e883b26c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -59,7 +59,7 @@ export default [ /* cli/*.js */ { - input: ['src/cli/index.js'], + input: ['src/cli/index.ts'], output: { dir: 'cli', format: 'cjs' @@ -71,7 +71,10 @@ export default [ plugins: [ json(), commonjs(), - resolve() + resolve(), + typescript({ + typescript: require('typescript') + }) ], experimentalDynamicImport: true, experimentalCodeSplitting: true diff --git a/src/cli/compile.js b/src/cli/compile.ts similarity index 100% rename from src/cli/compile.js rename to src/cli/compile.ts diff --git a/src/cli/error.js b/src/cli/error.ts similarity index 100% rename from src/cli/error.js rename to src/cli/error.ts diff --git a/src/cli/index.js b/src/cli/index.ts similarity index 100% rename from src/cli/index.js rename to src/cli/index.ts diff --git a/svelte b/svelte index 0297932340..527222ef56 100755 --- a/svelte +++ b/svelte @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('./cli/index.js'); \ No newline at end of file +require('./cli/index.ts.js'); \ No newline at end of file From 80b5156b174b4d746df81bed9664862267fef83c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 29 Apr 2018 20:47:03 -0400 Subject: [PATCH 4/7] just use normal promises --- src/cli/compile.ts | 2 +- src/cli/index.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cli/compile.ts b/src/cli/compile.ts index b22d489ea4..0b145be1e0 100644 --- a/src/cli/compile.ts +++ b/src/cli/compile.ts @@ -11,7 +11,7 @@ function mkdirp(dir) { if (!fs.existsSync(dir)) fs.mkdirSync(dir); } -export async function compile(input, opts) { +export function compile(input, opts) { if (opts._.length > 0) { error(`Can only compile a single file or directory`); } diff --git a/src/cli/index.ts b/src/cli/index.ts index 52137a6657..411d7f2f1d 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -21,9 +21,10 @@ prog .example('compile src -o dest') .example('compile -f umd MyComponent.html > MyComponent.js') - .action(async (input, opts) => { - const { compile } = await import('./compile.js'); - compile(input, opts); + .action((input, opts) => { + import('./compile.js').then(({ compile }) => { + compile(input, opts); + }); }) .parse(process.argv); \ No newline at end of file From 60516aff0dea7c1697b388c1533196f732f92e1a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 30 Apr 2018 09:07:47 -0400 Subject: [PATCH 5/7] update tests --- test/cli/samples/basic/actual/Main.js | 6 +++--- test/cli/samples/basic/expected/Main.js | 6 +++--- test/cli/samples/custom-element/actual/Main.js | 6 +++--- test/cli/samples/custom-element/expected/Main.js | 6 +++--- test/cli/samples/dir-sourcemap/actual/Main.js | 8 ++++---- test/cli/samples/dir-sourcemap/actual/Widget.js | 6 +++--- test/cli/samples/dir-sourcemap/expected/Main.js | 8 ++++---- test/cli/samples/dir-sourcemap/expected/Widget.js | 6 +++--- test/cli/samples/dir-subdir/actual/Main.js | 8 ++++---- test/cli/samples/dir-subdir/actual/widget/Widget.js | 6 +++--- test/cli/samples/dir-subdir/expected/Main.js | 8 ++++---- test/cli/samples/dir-subdir/expected/widget/Widget.js | 6 +++--- test/cli/samples/dir/actual/Main.js | 8 ++++---- test/cli/samples/dir/actual/Widget.js | 6 +++--- test/cli/samples/dir/expected/Main.js | 8 ++++---- test/cli/samples/dir/expected/Widget.js | 6 +++--- test/cli/samples/globals/actual/Main.js | 8 ++++---- test/cli/samples/globals/expected/Main.js | 8 ++++---- test/cli/samples/sourcemap-inline/actual/Main.js | 6 +++--- test/cli/samples/sourcemap-inline/expected/Main.js | 6 +++--- test/cli/samples/sourcemap/actual/Main.js | 6 +++--- test/cli/samples/sourcemap/expected/Main.js | 6 +++--- test/cli/samples/store/actual/Main.js | 8 ++++---- test/cli/samples/store/expected/Main.js | 8 ++++---- 24 files changed, 82 insertions(+), 82 deletions(-) diff --git a/test/cli/samples/basic/actual/Main.js b/test/cli/samples/basic/actual/Main.js index c9e83d1bcb..6514bbbd31 100644 --- a/test/cli/samples/basic/actual/Main.js +++ b/test/cli/samples/basic/actual/Main.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/basic/expected/Main.js b/test/cli/samples/basic/expected/Main.js index c9e83d1bcb..6514bbbd31 100644 --- a/test/cli/samples/basic/expected/Main.js +++ b/test/cli/samples/basic/expected/Main.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/custom-element/actual/Main.js b/test/cli/samples/custom-element/actual/Main.js index b14170bb99..e92ada81cd 100644 --- a/test/cli/samples/custom-element/actual/Main.js +++ b/test/cli/samples/custom-element/actual/Main.js @@ -4,19 +4,19 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; this.c = noop; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/custom-element/expected/Main.js b/test/cli/samples/custom-element/expected/Main.js index b14170bb99..e92ada81cd 100644 --- a/test/cli/samples/custom-element/expected/Main.js +++ b/test/cli/samples/custom-element/expected/Main.js @@ -4,19 +4,19 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; this.c = noop; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/dir-sourcemap/actual/Main.js b/test/cli/samples/dir-sourcemap/actual/Main.js index 755b86eb22..7cdd41dd4a 100644 --- a/test/cli/samples/dir-sourcemap/actual/Main.js +++ b/test/cli/samples/dir-sourcemap/actual/Main.js @@ -10,21 +10,21 @@ function create_main_fragment(component, ctx) { }); return { - c: function create() { + c() { widget._fragment.c(); }, - m: function mount(target, anchor) { + m(target, anchor) { widget._mount(target, anchor); }, p: noop, - u: function unmount() { + u() { widget._unmount(); }, - d: function destroy() { + d() { widget.destroy(false); } }; diff --git a/test/cli/samples/dir-sourcemap/actual/Widget.js b/test/cli/samples/dir-sourcemap/actual/Widget.js index 74e2b61f2a..ad16d7aef5 100644 --- a/test/cli/samples/dir-sourcemap/actual/Widget.js +++ b/test/cli/samples/dir-sourcemap/actual/Widget.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "widget"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/dir-sourcemap/expected/Main.js b/test/cli/samples/dir-sourcemap/expected/Main.js index 755b86eb22..7cdd41dd4a 100644 --- a/test/cli/samples/dir-sourcemap/expected/Main.js +++ b/test/cli/samples/dir-sourcemap/expected/Main.js @@ -10,21 +10,21 @@ function create_main_fragment(component, ctx) { }); return { - c: function create() { + c() { widget._fragment.c(); }, - m: function mount(target, anchor) { + m(target, anchor) { widget._mount(target, anchor); }, p: noop, - u: function unmount() { + u() { widget._unmount(); }, - d: function destroy() { + d() { widget.destroy(false); } }; diff --git a/test/cli/samples/dir-sourcemap/expected/Widget.js b/test/cli/samples/dir-sourcemap/expected/Widget.js index 74e2b61f2a..ad16d7aef5 100644 --- a/test/cli/samples/dir-sourcemap/expected/Widget.js +++ b/test/cli/samples/dir-sourcemap/expected/Widget.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "widget"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/dir-subdir/actual/Main.js b/test/cli/samples/dir-subdir/actual/Main.js index e2f801836d..52c9caf092 100644 --- a/test/cli/samples/dir-subdir/actual/Main.js +++ b/test/cli/samples/dir-subdir/actual/Main.js @@ -10,21 +10,21 @@ function create_main_fragment(component, ctx) { }); return { - c: function create() { + c() { widget._fragment.c(); }, - m: function mount(target, anchor) { + m(target, anchor) { widget._mount(target, anchor); }, p: noop, - u: function unmount() { + u() { widget._unmount(); }, - d: function destroy() { + d() { widget.destroy(false); } }; diff --git a/test/cli/samples/dir-subdir/actual/widget/Widget.js b/test/cli/samples/dir-subdir/actual/widget/Widget.js index 8dba93394a..66543c808e 100644 --- a/test/cli/samples/dir-subdir/actual/widget/Widget.js +++ b/test/cli/samples/dir-subdir/actual/widget/Widget.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "widget"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/dir-subdir/expected/Main.js b/test/cli/samples/dir-subdir/expected/Main.js index e2f801836d..52c9caf092 100644 --- a/test/cli/samples/dir-subdir/expected/Main.js +++ b/test/cli/samples/dir-subdir/expected/Main.js @@ -10,21 +10,21 @@ function create_main_fragment(component, ctx) { }); return { - c: function create() { + c() { widget._fragment.c(); }, - m: function mount(target, anchor) { + m(target, anchor) { widget._mount(target, anchor); }, p: noop, - u: function unmount() { + u() { widget._unmount(); }, - d: function destroy() { + d() { widget.destroy(false); } }; diff --git a/test/cli/samples/dir-subdir/expected/widget/Widget.js b/test/cli/samples/dir-subdir/expected/widget/Widget.js index 8dba93394a..66543c808e 100644 --- a/test/cli/samples/dir-subdir/expected/widget/Widget.js +++ b/test/cli/samples/dir-subdir/expected/widget/Widget.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "widget"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/dir/actual/Main.js b/test/cli/samples/dir/actual/Main.js index 046670e333..77a56bf3bf 100644 --- a/test/cli/samples/dir/actual/Main.js +++ b/test/cli/samples/dir/actual/Main.js @@ -10,21 +10,21 @@ function create_main_fragment(component, ctx) { }); return { - c: function create() { + c() { widget._fragment.c(); }, - m: function mount(target, anchor) { + m(target, anchor) { widget._mount(target, anchor); }, p: noop, - u: function unmount() { + u() { widget._unmount(); }, - d: function destroy() { + d() { widget.destroy(false); } }; diff --git a/test/cli/samples/dir/actual/Widget.js b/test/cli/samples/dir/actual/Widget.js index 10c9542744..ecb3303e7d 100644 --- a/test/cli/samples/dir/actual/Widget.js +++ b/test/cli/samples/dir/actual/Widget.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "widget"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/dir/expected/Main.js b/test/cli/samples/dir/expected/Main.js index 046670e333..77a56bf3bf 100644 --- a/test/cli/samples/dir/expected/Main.js +++ b/test/cli/samples/dir/expected/Main.js @@ -10,21 +10,21 @@ function create_main_fragment(component, ctx) { }); return { - c: function create() { + c() { widget._fragment.c(); }, - m: function mount(target, anchor) { + m(target, anchor) { widget._mount(target, anchor); }, p: noop, - u: function unmount() { + u() { widget._unmount(); }, - d: function destroy() { + d() { widget.destroy(false); } }; diff --git a/test/cli/samples/dir/expected/Widget.js b/test/cli/samples/dir/expected/Widget.js index 10c9542744..ecb3303e7d 100644 --- a/test/cli/samples/dir/expected/Widget.js +++ b/test/cli/samples/dir/expected/Widget.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "widget"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/globals/actual/Main.js b/test/cli/samples/globals/actual/Main.js index 829c294a1a..2db0a261a2 100644 --- a/test/cli/samples/globals/actual/Main.js +++ b/test/cli/samples/globals/actual/Main.js @@ -12,25 +12,25 @@ var Main = (function(answer) { "use strict"; var p, text, text_1; return { - c: function create() { + c() { p = createElement("p"); text = createText("The answer is "); text_1 = createText(ctx.answer); }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); appendNode(text, p); appendNode(text_1, p); }, - p: function update(changed, ctx) { + p(changed, ctx) { if (changed.answer) { text_1.data = ctx.answer; } }, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/globals/expected/Main.js b/test/cli/samples/globals/expected/Main.js index 829c294a1a..2db0a261a2 100644 --- a/test/cli/samples/globals/expected/Main.js +++ b/test/cli/samples/globals/expected/Main.js @@ -12,25 +12,25 @@ var Main = (function(answer) { "use strict"; var p, text, text_1; return { - c: function create() { + c() { p = createElement("p"); text = createText("The answer is "); text_1 = createText(ctx.answer); }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); appendNode(text, p); appendNode(text_1, p); }, - p: function update(changed, ctx) { + p(changed, ctx) { if (changed.answer) { text_1.data = ctx.answer; } }, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/sourcemap-inline/actual/Main.js b/test/cli/samples/sourcemap-inline/actual/Main.js index 4e95c96c37..fe639ac270 100644 --- a/test/cli/samples/sourcemap-inline/actual/Main.js +++ b/test/cli/samples/sourcemap-inline/actual/Main.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/sourcemap-inline/expected/Main.js b/test/cli/samples/sourcemap-inline/expected/Main.js index 4e95c96c37..fe639ac270 100644 --- a/test/cli/samples/sourcemap-inline/expected/Main.js +++ b/test/cli/samples/sourcemap-inline/expected/Main.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/sourcemap/actual/Main.js b/test/cli/samples/sourcemap/actual/Main.js index 2a532f70b1..4f303ce506 100644 --- a/test/cli/samples/sourcemap/actual/Main.js +++ b/test/cli/samples/sourcemap/actual/Main.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/sourcemap/expected/Main.js b/test/cli/samples/sourcemap/expected/Main.js index 2a532f70b1..4f303ce506 100644 --- a/test/cli/samples/sourcemap/expected/Main.js +++ b/test/cli/samples/sourcemap/expected/Main.js @@ -4,18 +4,18 @@ function create_main_fragment(component, ctx) { var p; return { - c: function create() { + c() { p = createElement("p"); p.textContent = "Hello world!"; }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(p, target, anchor); }, p: noop, - u: function unmount() { + u() { detachNode(p); }, diff --git a/test/cli/samples/store/actual/Main.js b/test/cli/samples/store/actual/Main.js index 228491d77a..3588e60789 100644 --- a/test/cli/samples/store/actual/Main.js +++ b/test/cli/samples/store/actual/Main.js @@ -4,25 +4,25 @@ function create_main_fragment(component, ctx) { var h1, text, text_1; return { - c: function create() { + c() { h1 = createElement("h1"); text = createText("Hello "); text_1 = createText(ctx.$name); }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(h1, target, anchor); appendNode(text, h1); appendNode(text_1, h1); }, - p: function update(changed, ctx) { + p(changed, ctx) { if (changed.$name) { text_1.data = ctx.$name; } }, - u: function unmount() { + u() { detachNode(h1); }, diff --git a/test/cli/samples/store/expected/Main.js b/test/cli/samples/store/expected/Main.js index 228491d77a..3588e60789 100644 --- a/test/cli/samples/store/expected/Main.js +++ b/test/cli/samples/store/expected/Main.js @@ -4,25 +4,25 @@ function create_main_fragment(component, ctx) { var h1, text, text_1; return { - c: function create() { + c() { h1 = createElement("h1"); text = createText("Hello "); text_1 = createText(ctx.$name); }, - m: function mount(target, anchor) { + m(target, anchor) { insertNode(h1, target, anchor); appendNode(text, h1); appendNode(text_1, h1); }, - p: function update(changed, ctx) { + p(changed, ctx) { if (changed.$name) { text_1.data = ctx.$name; } }, - u: function unmount() { + u() { detachNode(h1); }, From 86c273192f1b6b11527e284c9a33846f50f6da59 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 30 Apr 2018 09:11:44 -0400 Subject: [PATCH 6/7] rewrite version numbers to make cli testing less of a pain --- .gitignore | 1 + test/cli/index.js | 8 +- test/cli/samples/basic/actual/Main.js | 173 --------------- .../cli/samples/custom-element/actual/Main.js | 198 ------------------ test/cli/samples/dev/actual/Main.js | 197 ----------------- test/cli/samples/dir-sourcemap/actual/Main.js | 181 ---------------- .../samples/dir-sourcemap/actual/Main.js.map | 1 - .../samples/dir-sourcemap/actual/Widget.js | 174 --------------- .../dir-sourcemap/actual/Widget.js.map | 1 - test/cli/samples/dir-subdir/actual/Main.js | 180 ---------------- .../dir-subdir/actual/widget/Widget.js | 173 --------------- test/cli/samples/dir/actual/Main.js | 180 ---------------- test/cli/samples/dir/actual/Widget.js | 173 --------------- test/cli/samples/globals/actual/Main.js | 197 ----------------- .../samples/sourcemap-inline/actual/Main.js | 174 --------------- test/cli/samples/sourcemap/actual/Main.js | 174 --------------- test/cli/samples/sourcemap/actual/Main.js.map | 1 - test/cli/samples/ssr/actual/Main.js | 48 ----- test/cli/samples/store/actual/Main.js | 195 ----------------- 19 files changed, 8 insertions(+), 2421 deletions(-) delete mode 100644 test/cli/samples/basic/actual/Main.js delete mode 100644 test/cli/samples/custom-element/actual/Main.js delete mode 100644 test/cli/samples/dev/actual/Main.js delete mode 100644 test/cli/samples/dir-sourcemap/actual/Main.js delete mode 100644 test/cli/samples/dir-sourcemap/actual/Main.js.map delete mode 100644 test/cli/samples/dir-sourcemap/actual/Widget.js delete mode 100644 test/cli/samples/dir-sourcemap/actual/Widget.js.map delete mode 100644 test/cli/samples/dir-subdir/actual/Main.js delete mode 100644 test/cli/samples/dir-subdir/actual/widget/Widget.js delete mode 100644 test/cli/samples/dir/actual/Main.js delete mode 100644 test/cli/samples/dir/actual/Widget.js delete mode 100644 test/cli/samples/globals/actual/Main.js delete mode 100644 test/cli/samples/sourcemap-inline/actual/Main.js delete mode 100644 test/cli/samples/sourcemap/actual/Main.js delete mode 100644 test/cli/samples/sourcemap/actual/Main.js.map delete mode 100644 test/cli/samples/ssr/actual/Main.js delete mode 100644 test/cli/samples/store/actual/Main.js diff --git a/.gitignore b/.gitignore index b58299e656..25a75902db 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ node_modules /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/test/cli/index.js b/test/cli/index.js index 5bd623c0f1..f2b89c63c2 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -7,7 +7,10 @@ const glob = require('tiny-glob/sync.js'); const bin = path.resolve(`svelte`); function normalize(str) { - return str.replace(/^\s+$/gm, '').trim(); + return str + .replace(/^\s+$/gm, '') + .replace(/generated by Svelte v[.\d]+/, `generated by Svelte vx.y.z`) + .trim(); } const cwd = process.cwd(); @@ -57,6 +60,9 @@ describe('svelte-cli', () => { }; }); + console.log(actual); + console.log(expected); + actual.forEach((a, i) => { const e = expected[i]; diff --git a/test/cli/samples/basic/actual/Main.js b/test/cli/samples/basic/actual/Main.js deleted file mode 100644 index 6514bbbd31..0000000000 --- a/test/cli/samples/basic/actual/Main.js +++ /dev/null @@ -1,173 +0,0 @@ -/* 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/custom-element/actual/Main.js b/test/cli/samples/custom-element/actual/Main.js deleted file mode 100644 index e92ada81cd..0000000000 --- a/test/cli/samples/custom-element/actual/Main.js +++ /dev/null @@ -1,198 +0,0 @@ -/* 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/dev/actual/Main.js b/test/cli/samples/dev/actual/Main.js deleted file mode 100644 index 401307fe2e..0000000000 --- a/test/cli/samples/dev/actual/Main.js +++ /dev/null @@ -1,197 +0,0 @@ -/* 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/dir-sourcemap/actual/Main.js b/test/cli/samples/dir-sourcemap/actual/Main.js deleted file mode 100644 index 7cdd41dd4a..0000000000 --- a/test/cli/samples/dir-sourcemap/actual/Main.js +++ /dev/null @@ -1,181 +0,0 @@ -/* 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/actual/Main.js.map b/test/cli/samples/dir-sourcemap/actual/Main.js.map deleted file mode 100644 index cf890d4435..0000000000 --- a/test/cli/samples/dir-sourcemap/actual/Main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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/actual/Widget.js b/test/cli/samples/dir-sourcemap/actual/Widget.js deleted file mode 100644 index ad16d7aef5..0000000000 --- a/test/cli/samples/dir-sourcemap/actual/Widget.js +++ /dev/null @@ -1,174 +0,0 @@ -/* 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/actual/Widget.js.map b/test/cli/samples/dir-sourcemap/actual/Widget.js.map deleted file mode 100644 index d007680a81..0000000000 --- a/test/cli/samples/dir-sourcemap/actual/Widget.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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-subdir/actual/Main.js b/test/cli/samples/dir-subdir/actual/Main.js deleted file mode 100644 index 52c9caf092..0000000000 --- a/test/cli/samples/dir-subdir/actual/Main.js +++ /dev/null @@ -1,180 +0,0 @@ -/* 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/actual/widget/Widget.js b/test/cli/samples/dir-subdir/actual/widget/Widget.js deleted file mode 100644 index 66543c808e..0000000000 --- a/test/cli/samples/dir-subdir/actual/widget/Widget.js +++ /dev/null @@ -1,173 +0,0 @@ -/* 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/actual/Main.js b/test/cli/samples/dir/actual/Main.js deleted file mode 100644 index 77a56bf3bf..0000000000 --- a/test/cli/samples/dir/actual/Main.js +++ /dev/null @@ -1,180 +0,0 @@ -/* 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/actual/Widget.js b/test/cli/samples/dir/actual/Widget.js deleted file mode 100644 index ecb3303e7d..0000000000 --- a/test/cli/samples/dir/actual/Widget.js +++ /dev/null @@ -1,173 +0,0 @@ -/* 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/globals/actual/Main.js b/test/cli/samples/globals/actual/Main.js deleted file mode 100644 index 2db0a261a2..0000000000 --- a/test/cli/samples/globals/actual/Main.js +++ /dev/null @@ -1,197 +0,0 @@ -/* 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/sourcemap-inline/actual/Main.js b/test/cli/samples/sourcemap-inline/actual/Main.js deleted file mode 100644 index fe639ac270..0000000000 --- a/test/cli/samples/sourcemap-inline/actual/Main.js +++ /dev/null @@ -1,174 +0,0 @@ -/* 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/actual/Main.js b/test/cli/samples/sourcemap/actual/Main.js deleted file mode 100644 index 4f303ce506..0000000000 --- a/test/cli/samples/sourcemap/actual/Main.js +++ /dev/null @@ -1,174 +0,0 @@ -/* 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/actual/Main.js.map b/test/cli/samples/sourcemap/actual/Main.js.map deleted file mode 100644 index 5133d81436..0000000000 --- a/test/cli/samples/sourcemap/actual/Main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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/ssr/actual/Main.js b/test/cli/samples/ssr/actual/Main.js deleted file mode 100644 index adf4e19fa0..0000000000 --- a/test/cli/samples/ssr/actual/Main.js +++ /dev/null @@ -1,48 +0,0 @@ -"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/store/actual/Main.js b/test/cli/samples/store/actual/Main.js deleted file mode 100644 index 3588e60789..0000000000 --- a/test/cli/samples/store/actual/Main.js +++ /dev/null @@ -1,195 +0,0 @@ -/* 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 From c9494d93076a2ae158039a8bb6e8fc907ab9172b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 30 Apr 2018 10:42:37 -0400 Subject: [PATCH 7/7] add missing pkg.bin --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index aa65922f4b..7a035dfc3e 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "2.3.0", "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", + "bin": { + "svelte": "svelte" + }, "files": [ "cli", "compiler",