diff --git a/packages/svelte2tsx/src/utils/htmlxparser.ts b/packages/svelte2tsx/src/utils/htmlxparser.ts index bca7ec3e2..844593744 100644 --- a/packages/svelte2tsx/src/utils/htmlxparser.ts +++ b/packages/svelte2tsx/src/utils/htmlxparser.ts @@ -82,10 +82,13 @@ function blankVerbatimContent(htmlx: string, verbatimElements: Node[]) { for (const node of verbatimElements) { const content = node.content; if (content) { - output = - output.substring(0, content.start) + - output.substring(content.start, content.end).replace(/[^\n]/g, ' ') + - output.substring(content.end); + output = htmlx.substring(0, content.start) + + htmlx.substring(content.start, content.end) + // blank out the content + .replace(/[^\n]/g, ' ') + // excess blank space can make the svelte parser very slow (sec->min). break it up with comments (works in style/script) + .replace(/[^\n][^\n][^\n][^\n]\n/g, '/**/\n') + + htmlx.substring(content.end); } } return output; diff --git a/packages/svelte2tsx/test/htmlxparser/index.js b/packages/svelte2tsx/test/htmlxparser/index.js new file mode 100644 index 000000000..a0d296ec3 --- /dev/null +++ b/packages/svelte2tsx/test/htmlxparser/index.js @@ -0,0 +1,15 @@ +let converter = require('../build/htmlxtojsx') +let fs = require('fs') +let assert = require('assert') + +describe('htmlxparser', () => { + let content = fs.readFileSync(`${__dirname}/large.svelte`, {encoding: 'utf8'}); + + it('parses in a reasonable time', () => { + const start = new Date(); + converter.htmlx2jsx(content); + const elapsed = new Date() - start; + assert(elapsed <= 1000, `Parsing took ${elapsed} ms, which was longer than 1000ms`); + }) + +}); \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlxparser/large.svelte b/packages/svelte2tsx/test/htmlxparser/large.svelte new file mode 100644 index 000000000..b00d72b7c --- /dev/null +++ b/packages/svelte2tsx/test/htmlxparser/large.svelte @@ -0,0 +1,2273 @@ + + + \ No newline at end of file