mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #214 - Marko v3: <script marko-init>
This commit is contained in:
parent
d3f18a020e
commit
9abbf5d2ec
@ -222,6 +222,8 @@ class Parser {
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else if (attrName === 'marko-init') {
|
||||
return 'static-text';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -70,8 +70,21 @@ var coreAttrHandlers = [
|
||||
}
|
||||
],
|
||||
[
|
||||
'marko-preserve-whitespace', function(attr, node) {
|
||||
node.setPreserveWhitespace(true);
|
||||
'marko-preserve-whitespace', function(attr, node, el) {
|
||||
el.setPreserveWhitespace(true);
|
||||
}
|
||||
],
|
||||
[
|
||||
'marko-init', function(attr, node, el) {
|
||||
if (el.tagName !== 'script') {
|
||||
this.addError('The "marko-init" attribute should only be used on the <script> tag');
|
||||
return;
|
||||
}
|
||||
var bodyText = el.bodyText;
|
||||
el.noOutput = true;
|
||||
this.context.addStaticCode(bodyText);
|
||||
el.detach();
|
||||
return null;
|
||||
}
|
||||
]
|
||||
];
|
||||
@ -123,8 +136,11 @@ module.exports = function transform(el, context) {
|
||||
var newNode = attributeTransfomer[attrName](attr, node, el);
|
||||
if (newNode !== false) {
|
||||
el.removeAttribute(attrName);
|
||||
if (newNode) {
|
||||
newNode.pos = node.pos;
|
||||
if (newNode !== undefined) {
|
||||
if (newNode) {
|
||||
newNode.pos = node.pos;
|
||||
}
|
||||
|
||||
node = newNode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,11 +27,11 @@
|
||||
"preserve-whitespace": true
|
||||
},
|
||||
"<script>": {
|
||||
"preserve-whitespace": true
|
||||
},
|
||||
"<template-init>": {
|
||||
"code-generator": "./template-init-tag",
|
||||
"body": "static-text"
|
||||
"preserve-whitespace": true,
|
||||
"@marko-init": "boolean",
|
||||
"@*": {
|
||||
"ignore": true
|
||||
}
|
||||
},
|
||||
"<textarea>": {
|
||||
"preserve-whitespace": true
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
|
||||
|
||||
module.exports = function codeGenerator(elNode, codegen) {
|
||||
var bodyText = elNode.bodyText;
|
||||
elNode.noOutput = true;
|
||||
codegen.addStaticCode(bodyText);
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
---
|
||||
<template-init>
|
||||
<script marko-init>
|
||||
var name = '${name}<div if(foo)></div>';
|
||||
</template-init>
|
||||
</script>
|
||||
|
||||
Hello ${name}!
|
||||
---
|
||||
@ -1,7 +1,7 @@
|
||||
<template-init>
|
||||
<script marko-init>
|
||||
function greeting(name, out) {
|
||||
out.write('Hello ' + name + '!');
|
||||
}
|
||||
</template-init>
|
||||
</script>
|
||||
|
||||
<invoke greeting('Frank', out)/> <invoke greeting('John', out)/>
|
||||
@ -1,7 +1,7 @@
|
||||
---
|
||||
<template-init>
|
||||
<script marko-init>
|
||||
var testHelpers = require('./test-helpers')
|
||||
</template-init>
|
||||
</script>
|
||||
|
||||
Hello ${testHelpers.upperCase("world")}!
|
||||
Hello ${testHelpers.trim(" World ")}!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user