Skip to content

Commit

Permalink
fix: remove inline script source-url (#2850)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghangit authored Dec 21, 2023
1 parent b2d2c11 commit a826cf5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/empty-lions-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@qiankunjs/shared': patch
---

fix: remove inline script source-url
23 changes: 23 additions & 0 deletions packages/shared/src/assets-transpilers/__tests__/script.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, it, vi } from 'vitest';
import transpileScript from '../script';

it('inline script not include sourceURL', () => {
class MockSandbox {
makeEvaluateFactory(source: string, sourceURL?: string): string {
return '';
}
}

const code = 'console.log("hello world")';
const publicPath = 'http://localhost:8000';
const scriptElement = document.createElement('script');
scriptElement.innerHTML = code;
const sandboxInstance = new MockSandbox();
const makeEvaluateFactorySpy = vi.spyOn(sandboxInstance, 'makeEvaluateFactory');
transpileScript(scriptElement, publicPath, {
fetch: window.fetch,
rawNode: scriptElement,
sandbox: sandboxInstance,
});
expect(makeEvaluateFactorySpy).toHaveBeenCalledWith(code);
});
2 changes: 1 addition & 1 deletion packages/shared/src/assets-transpilers/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default function transpileScript(
const scriptNode = script.textContent ? script : rawNode.childNodes[0];
const { code } = result;

scriptNode.textContent = sandbox!.makeEvaluateFactory(code, baseURI);
scriptNode.textContent = sandbox!.makeEvaluateFactory(code);
// mark the script have consumed
script.dataset.consumed = 'true';

Expand Down

0 comments on commit a826cf5

Please sign in to comment.