-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'preserve-comments-option' of https://github.com/zzolo/s…
…velte into zzolo-preserve-comments-option
- Loading branch information
Showing
7 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
export default function visitComment() { | ||
// do nothing | ||
export default function visitComment( | ||
generator: SsrGenerator, | ||
block: Block, | ||
node: Node | ||
) { | ||
// Allow option to preserve comments, otherwise ignore | ||
if (generator && generator.options && generator.options.preserveComments) { | ||
generator.append(`<!--${node.data}-->`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
options: { | ||
generate: 'ssr', | ||
preserveComments: true | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var SvelteComponent = {}; | ||
SvelteComponent.data = function() { | ||
return {}; | ||
}; | ||
|
||
SvelteComponent.render = function(state, options = {}) { | ||
var components = new Set(); | ||
|
||
function addComponent(component) { | ||
components.add(component); | ||
} | ||
|
||
var result = { head: '', addComponent }; | ||
var html = SvelteComponent._render(result, state, options); | ||
|
||
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n'); | ||
|
||
return { | ||
html, | ||
head: result.head, | ||
css: { code: cssCode, map: null }, | ||
toString() { | ||
return html; | ||
} | ||
}; | ||
}; | ||
|
||
SvelteComponent._render = function(__result, state, options) { | ||
__result.addComponent(SvelteComponent); | ||
|
||
state = Object.assign({}, state); | ||
|
||
return `<div>content</div> | ||
<!-- comment --> | ||
<div>more content</div>`; | ||
}; | ||
|
||
SvelteComponent.css = { | ||
code: '', | ||
map: null | ||
}; | ||
|
||
var warned = false; | ||
SvelteComponent.renderCss = function() { | ||
if (!warned) { | ||
console.error('Component.renderCss(...) is deprecated and will be removed in v2 — use Component.render(...).css instead'); | ||
warned = true; | ||
} | ||
|
||
var components = []; | ||
|
||
return { | ||
css: components.map(x => x.css).join('\n'), | ||
map: null, | ||
components | ||
}; | ||
}; | ||
|
||
module.exports = SvelteComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"use strict"; | ||
|
||
var SvelteComponent = {};; | ||
|
||
SvelteComponent.data = function() { | ||
return {}; | ||
}; | ||
|
||
SvelteComponent.render = function(state, options = {}) { | ||
var components = new Set(); | ||
|
||
function addComponent(component) { | ||
components.add(component); | ||
} | ||
|
||
var result = { head: '', addComponent }; | ||
var html = SvelteComponent._render(result, state, options); | ||
|
||
var cssCode = Array.from(components).map(c => c.css && c.css.code).filter(Boolean).join('\n'); | ||
|
||
return { | ||
html, | ||
head: result.head, | ||
css: { code: cssCode, map: null }, | ||
toString() { | ||
return html; | ||
} | ||
}; | ||
} | ||
|
||
SvelteComponent._render = function(__result, state, options) { | ||
__result.addComponent(SvelteComponent); | ||
|
||
state = Object.assign({}, state); | ||
|
||
return `<div>content</div> | ||
<!-- comment --> | ||
<div>more content</div>`; | ||
}; | ||
|
||
SvelteComponent.css = { | ||
code: '', | ||
map: null | ||
}; | ||
|
||
var warned = false; | ||
SvelteComponent.renderCss = function() { | ||
if (!warned) { | ||
console.error('Component.renderCss(...) is deprecated and will be removed in v2 — use Component.render(...).css instead'); | ||
warned = true; | ||
} | ||
|
||
var components = []; | ||
|
||
return { | ||
css: components.map(x => x.css).join('\n'), | ||
map: null, | ||
components | ||
}; | ||
}; | ||
|
||
module.exports = SvelteComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div>content</div> | ||
<!-- comment --> | ||
<div>more content</div> |