diff --git a/package.json b/package.json index eca368922c..0db01e2b4d 100644 --- a/package.json +++ b/package.json @@ -16,12 +16,8 @@ "codecov": "codecov", "precodecov": "npm run coverage", "lint": "eslint src test/*.js", - "build": "npm run build:main && npm run build:shared && npm run build:ssr", - "build:main": "node src/shared/_build.js && rollup -c rollup/rollup.config.main.js", - "build:shared": "rollup -c rollup/rollup.config.shared.js", - "build:ssr": "rollup -c rollup/rollup.config.ssr.js", - "dev": "node src/shared/_build.js && rollup -c rollup/rollup.config.main.js -w", - "dev:shared": "rollup -c rollup/rollup.config.shared.js -w", + "build": "node src/shared/_build.js && rollup -c", + "dev": "node src/shared/_build.js && rollup -c -w", "pretest": "npm run build", "prepublish": "npm run build && npm run lint", "prettier": "prettier --use-tabs --single-quote --trailing-comma es5 --write \"src/**/*.ts\"" @@ -75,7 +71,7 @@ "nyc": "^10.0.0", "prettier": "^1.4.1", "reify": "^0.4.4", - "rollup": "^0.39.0", + "rollup": "^0.43.0", "rollup-plugin-buble": "^0.15.0", "rollup-plugin-commonjs": "^7.0.0", "rollup-plugin-json": "^2.1.0", diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000000..fe2a98494d --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,74 @@ +import path from 'path'; +import nodeResolve from 'rollup-plugin-node-resolve'; +import commonjs from 'rollup-plugin-commonjs'; +import json from 'rollup-plugin-json'; +import typescript from 'rollup-plugin-typescript'; +import buble from 'rollup-plugin-buble'; + +const src = path.resolve('src'); + +export default [ + /* compiler/svelte.js */ + { + entry: 'src/index.ts', + dest: 'compiler/svelte.js', + format: 'umd', + moduleName: 'svelte', + plugins: [ + { + resolveId(importee, importer) { + // bit of a hack — TypeScript only really works if it can resolve imports, + // but they misguidedly chose to reject imports with file extensions. This + // means we need to resolve them here + if ( + importer && + importer.startsWith(src) && + importee[0] === '.' && + path.extname(importee) === '' + ) { + return path.resolve(path.dirname(importer), `${importee}.ts`); + } + } + }, + nodeResolve({ jsnext: true, module: true }), + commonjs(), + json(), + typescript({ + include: 'src/**', + exclude: 'src/shared/**', + typescript: require('typescript') + }) + ], + sourceMap: true + }, + + /* ssr/register.js */ + { + entry: 'src/server-side-rendering/register.js', + dest: 'ssr/register.js', + format: 'cjs', + plugins: [ + nodeResolve({ jsnext: true, module: true }), + commonjs(), + buble({ + include: 'src/**', + exclude: 'src/shared/**', + target: { + node: 4 + } + }) + ], + external: [path.resolve('src/index.ts'), 'fs', 'path'], + paths: { + [path.resolve('src/index.ts')]: '../compiler/svelte.js' + }, + sourceMap: true + }, + + /* shared.js */ + { + entry: 'src/shared/index.js', + dest: 'shared.js', + format: 'es' + } +]; diff --git a/rollup/rollup.config.main.js b/rollup/rollup.config.main.js deleted file mode 100644 index c9ab0f7394..0000000000 --- a/rollup/rollup.config.main.js +++ /dev/null @@ -1,39 +0,0 @@ -import path from 'path'; -import nodeResolve from 'rollup-plugin-node-resolve'; -import commonjs from 'rollup-plugin-commonjs'; -import json from 'rollup-plugin-json'; -import typescript from 'rollup-plugin-typescript'; - -const src = path.resolve('src'); - -export default { - entry: 'src/index.ts', - moduleName: 'svelte', - targets: [{ dest: 'compiler/svelte.js', format: 'umd' }], - plugins: [ - { - resolveId(importee, importer) { - // bit of a hack — TypeScript only really works if it can resolve imports, - // but they misguidedly chose to reject imports with file extensions. This - // means we need to resolve them here - if ( - importer && - importer.startsWith(src) && - importee[0] === '.' && - path.extname(importee) === '' - ) { - return path.resolve(path.dirname(importer), `${importee}.ts`); - } - } - }, - nodeResolve({ jsnext: true, module: true }), - commonjs(), - json(), - typescript({ - include: 'src/**', - exclude: 'src/shared/**', - typescript: require('typescript') - }) - ], - sourceMap: true -}; diff --git a/rollup/rollup.config.shared.js b/rollup/rollup.config.shared.js deleted file mode 100644 index 1dda31ee6b..0000000000 --- a/rollup/rollup.config.shared.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - entry: 'src/shared/index.js', - dest: 'shared.js', - format: 'es' -}; diff --git a/rollup/rollup.config.ssr.js b/rollup/rollup.config.ssr.js deleted file mode 100644 index 6f9e9f6fe6..0000000000 --- a/rollup/rollup.config.ssr.js +++ /dev/null @@ -1,26 +0,0 @@ -import * as path from 'path'; -import nodeResolve from 'rollup-plugin-node-resolve'; -import commonjs from 'rollup-plugin-commonjs'; -import buble from 'rollup-plugin-buble'; - -export default { - entry: 'src/server-side-rendering/register.js', - moduleName: 'svelte', - targets: [{ dest: 'ssr/register.js', format: 'cjs' }], - plugins: [ - nodeResolve({ jsnext: true, module: true }), - commonjs(), - buble({ - include: 'src/**', - exclude: 'src/shared/**', - target: { - node: 4 - } - }) - ], - external: [path.resolve('src/index.ts'), 'fs', 'path'], - paths: { - [path.resolve('src/index.ts')]: '../compiler/svelte.js' - }, - sourceMap: true -}; diff --git a/src/parse/utils/hash.ts b/src/parse/utils/hash.ts index 8f2221ee49..8bc550a5c0 100644 --- a/src/parse/utils/hash.ts +++ b/src/parse/utils/hash.ts @@ -3,6 +3,6 @@ export default function hash(str: string): number { let hash = 5381; let i = str.length; - while (i--) hash = (hash * 33) ^ str.charCodeAt(i); + while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i); return hash >>> 0; } diff --git a/src/shared/transitions.js b/src/shared/transitions.js index df03646510..30b5c73342 100644 --- a/src/shared/transitions.js +++ b/src/shared/transitions.js @@ -5,37 +5,31 @@ export function linear(t) { return t; } -export function generateKeyframes( +export function generateRule( a, b, delta, duration, ease, - fn, - node, - style + fn ) { - var id = '__svelte' + ~~(Math.random() * 1e9); // TODO make this more robust - var keyframes = '@keyframes ' + id + '{\n'; + var keyframes = '{\n'; for (var p = 0; p <= 1; p += 16.666 / duration) { var t = a + delta * ease(p); keyframes += p * 100 + '%{' + fn(t) + '}\n'; } - keyframes += '100% {' + fn(b) + '}\n}'; - style.textContent += keyframes; + return keyframes + '100% {' + fn(b) + '}\n}'; +} - document.head.appendChild(style); +// https://github.com/darkskyapp/string-hash/blob/master/index.js +export function hash(str) { + var hash = 5381; + var i = str.length; - node.style.animation = (node.style.animation || '') - .split(',') - .filter(function(anim) { - // when introing, discard old animations if there are any - return anim && (delta < 0 || !/__svelte/.test(anim)); - }) - .concat(id + ' ' + duration + 'ms linear 1 forwards') - .join(', '); + while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i); + return hash >>> 0; } export function wrapTransition(node, fn, params, intro, outgroup) { @@ -45,8 +39,10 @@ export function wrapTransition(node, fn, params, intro, outgroup) { var cssText; // TODO share