Skip to content

Commit a44398b

Browse files
committed
snapshot
1 parent 8f892bf commit a44398b

File tree

31 files changed

+406
-283
lines changed

31 files changed

+406
-283
lines changed

compiler/parse/__test__.js

Lines changed: 0 additions & 196 deletions
This file was deleted.

compiler/parse/index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,31 @@ export default function parse ( template ) {
6363
}
6464

6565
this.allowWhitespace();
66-
}
67-
};
66+
},
6867

69-
const html = {
70-
start: 0,
71-
end: template.length,
72-
type: 'Fragment',
73-
children: []
74-
};
68+
html: {
69+
start: 0,
70+
end: template.length,
71+
type: 'Fragment',
72+
children: []
73+
},
7574

76-
let css = null;
77-
let js = null;
75+
css: null,
7876

79-
parser.stack.push( html );
77+
js: null
78+
};
79+
80+
parser.stack.push( parser.html );
8081

8182
let state = fragment;
8283

8384
while ( parser.index < parser.template.length ) {
8485
state = state( parser ) || fragment;
8586
}
8687

87-
return { html, css, js };
88+
return {
89+
html: parser.html,
90+
css: parser.css,
91+
js: parser.js
92+
};
8893
}

compiler/parse/read/script.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { parse, tokenizer, tokTypes } from 'acorn';
2+
3+
export default function readScript ( parser, start, attributes ) {
4+
const scriptStart = parser.index;
5+
let scriptEnd = null;
6+
7+
const js = {
8+
start,
9+
end: null,
10+
attributes,
11+
content: null
12+
};
13+
14+
const endPattern = /\s*<\/script\>/g;
15+
16+
for ( const token of tokenizer( parser.remaining() ) ) {
17+
endPattern.lastIndex = scriptStart + token.end;
18+
if ( endPattern.test( parser.template ) ) {
19+
scriptEnd = scriptStart + token.end;
20+
break;
21+
}
22+
}
23+
24+
js.content = parse( )
25+
}

compiler/parse/read/style.js

Whitespace-only changes.

compiler/parse/state/tag.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import readExpression from '../read/expression.js';
2+
import readScript from '../read/script.js';
3+
import readStyle from '../read/style.js';
24

35
const validTagName = /^[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/;
46
const voidElementNames = /^(?:area|base|br|col|command|doctype|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)$/i;
57

8+
const specials = {
9+
script: {
10+
read: readScript,
11+
property: 'js'
12+
},
13+
14+
style: {
15+
read: readStyle,
16+
property: 'css'
17+
}
18+
};
19+
620
export default function tag ( parser ) {
721
const start = parser.index++;
822

@@ -30,6 +44,20 @@ export default function tag ( parser ) {
3044

3145
parser.allowWhitespace();
3246

47+
// special cases – <script> and <style>
48+
if ( name in specials ) {
49+
const special = specials[ name ];
50+
51+
if ( parser[ special.id ] ) {
52+
parser.index = start;
53+
parser.error( `You can only have one <${name}> tag per component` );
54+
}
55+
56+
parser.eat( '>', true );
57+
parser[ special.id ] = special.read( parser, start, attributes );
58+
return;
59+
}
60+
3361
const element = {
3462
start,
3563
end: null, // filled in later
@@ -43,9 +71,7 @@ export default function tag ( parser ) {
4371

4472
const selfClosing = parser.eat( '/' ) || voidElementNames.test( name );
4573

46-
if ( !parser.eat( '>' ) ) {
47-
parser.error( `Expected >` );
48-
}
74+
parser.eat( '>', true );
4975

5076
if ( selfClosing ) {
5177
element.end = parser.index;

test/compiler/default-data/_config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as assert from 'assert';
2+
3+
export default {
4+
description: 'hello world',
5+
html: '<h1>Hello world!</h1>'
6+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h1>Hello {{name}}!</h1>
2+
3+
<script>
4+
export default {
5+
data: () => ({
6+
name: 'world'
7+
})
8+
};
9+
</script>

0 commit comments

Comments
 (0)