Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trim SSR'd output more intelligently #998

Merged
merged 34 commits into from
Dec 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2e56d10
start moving logic into Node and its subclasses
Rich-Harris Dec 6, 2017
4b31992
remove unused code
Rich-Harris Dec 6, 2017
39f1af2
start implementing build() methods
Rich-Harris Dec 7, 2017
8e9e323
start moving build logic into individual nodes
Rich-Harris Dec 9, 2017
c6d49b7
move some code around
Rich-Harris Dec 9, 2017
daaad80
remove some unused code
Rich-Harris Dec 9, 2017
e8e05e7
move Slot logic
Rich-Harris Dec 9, 2017
425d019
move attribute logic
Rich-Harris Dec 9, 2017
8072f6a
move binding logic
Rich-Harris Dec 9, 2017
596c432
move shared MustacheTag/RawMustacheTag logic
Rich-Harris Dec 9, 2017
56f34c7
remove elementStack
Rich-Harris Dec 9, 2017
fd24a5c
remove componentStack
Rich-Harris Dec 9, 2017
0cf9259
remove inEachBlock
Rich-Harris Dec 9, 2017
67aca17
Merge branch 'master' into gh-979
Rich-Harris Dec 9, 2017
f4888dd
fix a few typescript issues
Rich-Harris Dec 9, 2017
7f77a10
remove confusing state object from init
Rich-Harris Dec 9, 2017
f6ac3a4
remove some unused stuff
Rich-Harris Dec 9, 2017
e30dc8e
put namespace on Element nodes
Rich-Harris Dec 9, 2017
8eacc25
tidy up
Rich-Harris Dec 9, 2017
48ed685
more tidying up
Rich-Harris Dec 9, 2017
05d63e6
simplify
Rich-Harris Dec 9, 2017
16bac3b
more simplification
Rich-Harris Dec 9, 2017
433623c
rename some stuff to be clearer
Rich-Harris Dec 9, 2017
afa996c
remove unused imports
Rich-Harris Dec 9, 2017
e9dc123
DRY out
Rich-Harris Dec 9, 2017
ea418cd
more tidying up
Rich-Harris Dec 9, 2017
3fa83e3
rename _block to block
Rich-Harris Dec 9, 2017
9b2a7e1
remove preprocess from ssr renderer
Rich-Harris Dec 9, 2017
e974fdc
more tidying up
Rich-Harris Dec 9, 2017
a72a6ca
small tweak, possibly ahead of a much larger one
Rich-Harris Dec 9, 2017
f7d4994
tidy up
Rich-Harris Dec 9, 2017
cf94217
remove unused code
Rich-Harris Dec 10, 2017
781d722
trim SSRd output more intelligently - fixes #976
Rich-Harris Dec 10, 2017
3b2404d
Merge branch 'master' into gh-976
Rich-Harris Dec 10, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/generators/server-side-rendering/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function ssr(
conditions: [],
});

parsed.html.children.forEach((node: Node) => {
trim(parsed.html.children).forEach((node: Node) => {
visit(generator, mainBlock, node);
});

Expand Down Expand Up @@ -122,7 +122,7 @@ export default function ssr(
}
`}

return \`${generator.renderCode}\`.trim();
return \`${generator.renderCode}\`;
};

${name}.renderCss = function() {
Expand Down Expand Up @@ -202,3 +202,25 @@ export default function ssr(

return generator.generate(result, options, { name, format });
}

function trim(nodes) {
let start = 0;
for (; start < nodes.length; start += 1) {
const node = nodes[start];
if (node.type !== 'Text') break;

node.data = node.data.replace(/^\s+/, '');
if (node.data) break;
}

let end = nodes.length;
for (; end > start; end -= 1) {
const node = nodes[end - 1];
if (node.type !== 'Text') break;

node.data = node.data.replace(/\s+$/, '');
if (node.data) break;
}

return nodes.slice(start, end);
}
2 changes: 1 addition & 1 deletion test/js/samples/ssr-no-oncreate-etc/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SvelteComponent.data = function() {
SvelteComponent.render = function(state, options = {}) {
state = Object.assign({}, state);

return ``.trim();
return ``;
};

SvelteComponent.renderCss = function() {
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/ssr-no-oncreate-etc/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SvelteComponent.data = function() {
SvelteComponent.render = function(state, options = {}) {
state = Object.assign({}, state);

return ``.trim();
return ``;
};

SvelteComponent.renderCss = function() {
Expand Down