0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

transpile/remove stuff that wont work in Node 4

This commit is contained in:
Rich-Harris 2017-03-07 12:05:41 -05:00
parent 43a5c6edd5
commit 55f3ed42d9
7 changed files with 37 additions and 23 deletions

View File

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

View File

@ -1,6 +1,7 @@
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',
@ -10,7 +11,14 @@ export default {
],
plugins: [
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' ],
paths: {

View File

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

View File

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

View File

@ -82,18 +82,18 @@ export default function addComponentAttributes ( generator, node, local ) {
generator.addSourcemapLocations( attribute.expression );
generator.code.prependRight( attribute.expression.start, 'component.' );
const usedContexts = new Set();
const usedContexts = [];
attribute.expression.arguments.forEach( arg => {
const { contexts } = generator.contextualise( arg, true, true );
contexts.forEach( context => {
usedContexts.add( context );
local.allUsedContexts.add( context );
if ( !~usedContexts.indexOf( context ) ) usedContexts.push( context );
if ( !~local.allUsedContexts.indexOf( context ) ) local.allUsedContexts.push( context );
});
});
// 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;';
const listName = generator.current.listNames[ name ];

View File

@ -155,18 +155,18 @@ export default function addElementAttributes ( generator, node, local ) {
generator.code.prependRight( attribute.expression.start, 'component.' );
}
const usedContexts = new Set();
const usedContexts = [];
attribute.expression.arguments.forEach( arg => {
const { contexts } = generator.contextualise( arg, true );
contexts.forEach( context => {
usedContexts.add( context );
local.allUsedContexts.add( context );
if ( !~usedContexts.indexOf( context ) ) usedContexts.push( context );
if ( !~local.allUsedContexts.indexOf( context ) ) local.allUsedContexts.push( context );
});
});
// 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;';
const listName = generator.current.listNames[ name ];

View File

@ -8,7 +8,9 @@ export default function createBinding ( generator, node, attribute, current, loc
const deep = parts.length > 1;
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 ) {
let obj;