transpile/remove stuff that wont work in Node 4

pull/353/head
Rich-Harris 8 years ago
parent 43a5c6edd5
commit 55f3ed42d9

@ -1,6 +1,7 @@
import nodeResolve from 'rollup-plugin-node-resolve'; import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs'; import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json'; import json from 'rollup-plugin-json';
import buble from 'rollup-plugin-buble';
export default { export default {
entry: 'src/index.js', entry: 'src/index.js',
@ -11,7 +12,14 @@ export default {
plugins: [ plugins: [
nodeResolve({ jsnext: true, module: true }), nodeResolve({ jsnext: true, module: true }),
commonjs(), commonjs(),
json() json(),
buble({
include: 'src/**',
exclude: 'src/shared/**',
transforms: {
dangerousTaggedTemplateString: true
}
})
], ],
external: [ 'magic-string' ], external: [ 'magic-string' ],
globals: { globals: {

@ -1,6 +1,7 @@
import * as path from 'path'; import * as path from 'path';
import nodeResolve from 'rollup-plugin-node-resolve'; import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs'; import commonjs from 'rollup-plugin-commonjs';
import buble from 'rollup-plugin-buble';
export default { export default {
entry: 'src/server-side-rendering/register.js', entry: 'src/server-side-rendering/register.js',
@ -10,7 +11,14 @@ export default {
], ],
plugins: [ plugins: [
nodeResolve({ jsnext: true, module: true }), nodeResolve({ jsnext: true, module: true }),
commonjs() commonjs(),
buble({
include: 'src/**',
exclude: 'src/shared/**',
transforms: {
dangerousTaggedTemplateString: true
}
})
], ],
external: [ path.resolve( 'src/index.js' ), 'fs', 'path', 'magic-string' ], external: [ path.resolve( 'src/index.js' ), 'fs', 'path', 'magic-string' ],
paths: { paths: {

@ -16,7 +16,7 @@ export default {
namespace: generator.current.namespace, namespace: generator.current.namespace,
isComponent: true, isComponent: true,
allUsedContexts: new Set(), allUsedContexts: [],
init: new CodeBuilder(), init: new CodeBuilder(),
update: new CodeBuilder() update: new CodeBuilder()
@ -28,10 +28,8 @@ export default {
addComponentAttributes( generator, node, local ); addComponentAttributes( generator, node, local );
if ( local.allUsedContexts.size ) { if ( local.allUsedContexts.length ) {
const contextNames = [...local.allUsedContexts]; const initialProps = local.allUsedContexts.map( contextName => {
const initialProps = contextNames.map( contextName => {
if ( contextName === 'root' ) return `root: root`; if ( contextName === 'root' ) return `root: root`;
const listName = generator.current.listNames[ contextName ]; const listName = generator.current.listNames[ contextName ];
@ -40,7 +38,7 @@ export default {
return `${listName}: ${listName},\n${indexName}: ${indexName}`; return `${listName}: ${listName},\n${indexName}: ${indexName}`;
}).join( ',\n' ); }).join( ',\n' );
const updates = contextNames.map( contextName => { const updates = local.allUsedContexts.map( contextName => {
if ( contextName === 'root' ) return `${name}._context.root = root;`; if ( contextName === 'root' ) return `${name}._context.root = root;`;
const listName = generator.current.listNames[ contextName ]; const listName = generator.current.listNames[ contextName ];

@ -17,7 +17,7 @@ export default {
namespace: node.name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace, namespace: node.name === 'svg' ? 'http://www.w3.org/2000/svg' : generator.current.namespace,
isComponent: false, isComponent: false,
allUsedContexts: new Set(), allUsedContexts: [],
init: new CodeBuilder(), init: new CodeBuilder(),
update: new CodeBuilder() update: new CodeBuilder()
@ -27,10 +27,8 @@ export default {
addElementAttributes( generator, node, local ); addElementAttributes( generator, node, local );
if ( local.allUsedContexts.size ) { if ( local.allUsedContexts.length ) {
const contextNames = [...local.allUsedContexts]; const initialProps = local.allUsedContexts.map( contextName => {
const initialProps = contextNames.map( contextName => {
if ( contextName === 'root' ) return `root: root`; if ( contextName === 'root' ) return `root: root`;
const listName = generator.current.listNames[ contextName ]; const listName = generator.current.listNames[ contextName ];
@ -39,7 +37,7 @@ export default {
return `${listName}: ${listName},\n${indexName}: ${indexName}`; return `${listName}: ${listName},\n${indexName}: ${indexName}`;
}).join( ',\n' ); }).join( ',\n' );
const updates = contextNames.map( contextName => { const updates = local.allUsedContexts.map( contextName => {
if ( contextName === 'root' ) return `${name}.__svelte.root = root;`; if ( contextName === 'root' ) return `${name}.__svelte.root = root;`;
const listName = generator.current.listNames[ contextName ]; const listName = generator.current.listNames[ contextName ];

@ -82,18 +82,18 @@ export default function addComponentAttributes ( generator, node, local ) {
generator.addSourcemapLocations( attribute.expression ); generator.addSourcemapLocations( attribute.expression );
generator.code.prependRight( attribute.expression.start, 'component.' ); generator.code.prependRight( attribute.expression.start, 'component.' );
const usedContexts = new Set(); const usedContexts = [];
attribute.expression.arguments.forEach( arg => { attribute.expression.arguments.forEach( arg => {
const { contexts } = generator.contextualise( arg, true, true ); const { contexts } = generator.contextualise( arg, true, true );
contexts.forEach( context => { contexts.forEach( context => {
usedContexts.add( context ); if ( !~usedContexts.indexOf( context ) ) usedContexts.push( context );
local.allUsedContexts.add( context ); if ( !~local.allUsedContexts.indexOf( context ) ) local.allUsedContexts.push( context );
}); });
}); });
// TODO hoist event handlers? can do `this.__component.method(...)` // TODO hoist event handlers? can do `this.__component.method(...)`
const declarations = [...usedContexts].map( name => { const declarations = usedContexts.map( name => {
if ( name === 'root' ) return 'var root = this._context.root;'; if ( name === 'root' ) return 'var root = this._context.root;';
const listName = generator.current.listNames[ name ]; const listName = generator.current.listNames[ name ];

@ -155,18 +155,18 @@ export default function addElementAttributes ( generator, node, local ) {
generator.code.prependRight( attribute.expression.start, 'component.' ); generator.code.prependRight( attribute.expression.start, 'component.' );
} }
const usedContexts = new Set(); const usedContexts = [];
attribute.expression.arguments.forEach( arg => { attribute.expression.arguments.forEach( arg => {
const { contexts } = generator.contextualise( arg, true ); const { contexts } = generator.contextualise( arg, true );
contexts.forEach( context => { contexts.forEach( context => {
usedContexts.add( context ); if ( !~usedContexts.indexOf( context ) ) usedContexts.push( context );
local.allUsedContexts.add( context ); if ( !~local.allUsedContexts.indexOf( context ) ) local.allUsedContexts.push( context );
}); });
}); });
// TODO hoist event handlers? can do `this.__component.method(...)` // TODO hoist event handlers? can do `this.__component.method(...)`
const declarations = [...usedContexts].map( name => { const declarations = usedContexts.map( name => {
if ( name === 'root' ) return 'var root = this.__svelte.root;'; if ( name === 'root' ) return 'var root = this.__svelte.root;';
const listName = generator.current.listNames[ name ]; const listName = generator.current.listNames[ name ];

@ -8,7 +8,9 @@ export default function createBinding ( generator, node, attribute, current, loc
const deep = parts.length > 1; const deep = parts.length > 1;
const contextual = parts[0] in current.contexts; const contextual = parts[0] in current.contexts;
if ( contextual ) local.allUsedContexts.add( parts[0] ); if ( contextual && !~local.allUsedContexts.indexOf( parts[0] ) ) {
local.allUsedContexts.push( parts[0] );
}
if ( local.isComponent ) { if ( local.isComponent ) {
let obj; let obj;

Loading…
Cancel
Save