From be14f25788c339484c7a513c0120f232fa5d7235 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 9 Feb 2016 16:54:31 -0500 Subject: [PATCH 1/2] rename existing tests --- test/parse/input/{withImport.html => withSubcomponent.html} | 0 test/parse/output/{withImport.json => withSubcomponent.json} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/parse/input/{withImport.html => withSubcomponent.html} (100%) rename test/parse/output/{withImport.json => withSubcomponent.json} (100%) diff --git a/test/parse/input/withImport.html b/test/parse/input/withSubcomponent.html similarity index 100% rename from test/parse/input/withImport.html rename to test/parse/input/withSubcomponent.html diff --git a/test/parse/output/withImport.json b/test/parse/output/withSubcomponent.json similarity index 100% rename from test/parse/output/withImport.json rename to test/parse/output/withSubcomponent.json From 8ddafed9f9a3986f6fea4c5efbfa2c5e5a747c75 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 9 Feb 2016 18:38:05 -0500 Subject: [PATCH 2/2] support export default (part of #15) --- package.json | 2 +- src/parse.js | 6 ++++-- test/parse/input/withExportDefault.html | 9 +++++++++ test/parse/output/withExportDefault.json | 10 ++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/parse/input/withExportDefault.html create mode 100644 test/parse/output/withExportDefault.json diff --git a/package.json b/package.json index 3222246..a738afa 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "repository": "https://github.com/ractivejs/rcu", "dependencies": { "eval2": "^0.3.0", - "tippex": "^1.1.0", + "tippex": "^1.2.0", "vlq": "^0.2.0" }, "devDependencies": { diff --git a/src/parse.js b/src/parse.js index 19863ab..8ddaefc 100644 --- a/src/parse.js +++ b/src/parse.js @@ -1,4 +1,4 @@ -import { match } from 'tippex'; +import { match, replace } from 'tippex'; import { Ractive } from './init.js'; import getName from './getName.js'; import getLinePosition from './utils/getLinePosition.js'; @@ -93,7 +93,9 @@ export default function parse ( source ) { result.scriptStart = getLinePosition( lines, contentStart ); result.scriptEnd = getLinePosition( lines, contentEnd ); - result.script = source.slice( contentStart, contentEnd ); + const script = source.slice( contentStart, contentEnd ); + + result.script = replace( script, /export\s+default\s+/, () => 'component.exports = ' ); match( result.script, requirePattern, ( match, doubleQuoted, singleQuoted ) => { const source = doubleQuoted || singleQuoted; diff --git a/test/parse/input/withExportDefault.html b/test/parse/input/withExportDefault.html new file mode 100644 index 0000000..c04c418 --- /dev/null +++ b/test/parse/input/withExportDefault.html @@ -0,0 +1,9 @@ +

Hello world!

+ + diff --git a/test/parse/output/withExportDefault.json b/test/parse/output/withExportDefault.json new file mode 100644 index 0000000..4c2432b --- /dev/null +++ b/test/parse/output/withExportDefault.json @@ -0,0 +1,10 @@ +{ + "source": "

Hello world!

\n\n\n", + "template": {"v":3,"t":[{"t":7,"e":"h1","f":["Hello world!"],"p":[1,1,0]}]}, + "script": "\n\tcomponent.exports = {\n\t\toninit: function () {\n\t\t\tconsole.log( 'hello world' );\n\t\t}\n\t};\n", + "scriptStart": { "line": 2, "column": 8, "char": 31 }, + "scriptEnd": { "line": 8, "column": 0, "char": 115 }, + "css": "", + "imports": [], + "modules": [] +}