Skip to content

Commit

Permalink
transpile/remove stuff that wont work in Node 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 7, 2017
1 parent 43a5c6e commit 55f3ed4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
10 changes: 9 additions & 1 deletion rollup/rollup.config.main.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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: {
Expand Down
10 changes: 9 additions & 1 deletion rollup/rollup.config.ssr.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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: {
Expand Down
10 changes: 4 additions & 6 deletions src/generators/dom/visitors/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
namespace: generator.current.namespace,
isComponent: true,

allUsedContexts: new Set(),
allUsedContexts: [],

init: new CodeBuilder(),
update: new CodeBuilder()
Expand All @@ -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 ];
Expand All @@ -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 ];
Expand Down
10 changes: 4 additions & 6 deletions src/generators/dom/visitors/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 ];
Expand All @@ -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 ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
4 changes: 3 additions & 1 deletion src/generators/dom/visitors/attributes/binding/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 55f3ed4

Please sign in to comment.