Skip to content

Commit

Permalink
Update internal Rollup plugin removing from output with Rollup 1.0 ch…
Browse files Browse the repository at this point in the history
…anges (ampproject#225)
  • Loading branch information
kristoferbaxter authored Jan 10, 2019
1 parent 24976fe commit 160e319
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
25 changes: 11 additions & 14 deletions config/rollup.plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,20 @@ export function removeTestingDocument() {
buildStart() {
context = this;
},
transformChunk: async (code) => {
renderChunk: async (code) => {
const source = new MagicString(code);
const program = context.parse(code, { ranges: true });

if (context) {
const program = context.parse(code, { ranges: true });

walk.simple(program, {
VariableDeclarator(node) {
if (node.id && node.id.type === 'Identifier' && node.id.name && node.id.name === 'documentForTesting') {
const range = node.range;
if (range) {
source.overwrite(node.range[0], node.range[1], 'documentForTesting = undefined');
}
walk.simple(program, {
VariableDeclarator(node) {
if (node.id && node.id.type === 'Identifier' && node.id.name && node.id.name === 'documentForTesting') {
const range = node.range;
if (range) {
source.overwrite(node.range[0], node.range[1], 'documentForTesting = undefined');
}
},
});
}
}
},
});

return {
code: source.toString(),
Expand Down
3 changes: 3 additions & 0 deletions src/worker-thread/dom/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ export function createDocument(postMessageMethod?: Function): Document {

return doc;
}

/** Should only be used for testing. */
export const documentForTesting = createDocument();

0 comments on commit 160e319

Please sign in to comment.