Unverified Commit a5e3afa2 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

turbopack: test PURE-annotated callees with execution tests

Replace the unit and snapshot tests with execution tests that check the side effects actually run, with and without scope hoisting. Make ReadOnlyComments panic on unsupported mutations and read flags without mutating the comment stores; moves stay no-ops because the fixer calls them for every removed paren.
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 3fd1c243
...@@ -75,7 +75,7 @@ test/development/mcp-server/fixtures/compilation-errors-app/app/syntax-error/pag ...@@ -75,7 +75,7 @@ test/development/mcp-server/fixtures/compilation-errors-app/app/syntax-error/pag
/test/development/app-dir/css-parse-error-recovery/app/css-error/style.css /test/development/app-dir/css-parse-error-recovery/app/css-error/style.css
/turbopack/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs /turbopack/crates/turbopack-tests/tests/snapshot/import-meta/cjs/input/mod.cjs
# prettier removes the parentheses that scope the PURE annotation to the inner call # prettier removes the parentheses that scope the PURE annotation to the inner call
/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-*/input/index.js /turbopack/crates/turbopack-tests/tests/execution/turbopack/minification/pure-annotated-callee*/input/index.js
/turbopack/crates/turbopack-tests/tests/snapshot/source_maps/* /turbopack/crates/turbopack-tests/tests/snapshot/source_maps/*
/turbopack/crates/turbopack-tests/tests/**/output* /turbopack/crates/turbopack-tests/tests/**/output*
/turbopack/crates/turbopack-tests/tests/**/static /turbopack/crates/turbopack-tests/tests/**/static
......
import { __name } from './name.js'
const calls = []
function make() {
return {
run() {
calls.push('member')
},
}
}
// The PURE annotations below apply only to the inner, parenthesized calls. The
// outer calls have side effects and must not be removed by the minifier.
;(/* @__PURE__ */ __name(function annotated() {
calls.push('iife')
}, 'annotated'))()
;(/* @__PURE__ */ make()).run()
it('should keep calls whose callee is a PURE-annotated call', () => {
expect(calls).toEqual(['iife', 'member'])
})
// esbuild's `keepNames` helpers.
var __defProp = Object.defineProperty var __defProp = Object.defineProperty
export var __name = (target, value) => export var __name = (target, value) =>
......
import { __name } from './name.js'
const calls = []
function make() {
return {
run() {
calls.push('member')
},
}
}
// The PURE annotations below apply only to the inner, parenthesized calls. The
// outer calls have side effects and must not be removed by the minifier.
;(/* @__PURE__ */ __name(function annotated() {
calls.push('iife')
}, 'annotated'))()
;(/* @__PURE__ */ make()).run()
it('should keep calls whose callee is a PURE-annotated call', () => {
expect(calls).toEqual(['iife', 'member'])
})
// esbuild's `keepNames` helpers.
var __defProp = Object.defineProperty
export var __name = (target, value) =>
__defProp(target, 'name', { value, configurable: true })
import { __name } from './name.js'
// The PURE annotation applies to the inner `__name(...)` call only. The outer
// call (the IIFE) has side effects and must be kept.
;(/* @__PURE__ */ __name(function annotated() {
console.log('annotated IIFE ran')
}, 'annotated'))()
export const value = 1
{
"minifyType": {
"Minify": {
"mangle": "optimal-size"
}
},
"scopeHoisting": true
}
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/0nf9_minification_pure-annotated-iife-scope-hoisted_input_index_10cuajmww7lap.js",{otherChunks:["output/154e_minification_pure-annotated-iife-scope-hoisted_input_index_0z5laqz7qel98.js"],runtimeModuleIds:["[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife-scope-hoisted/input/index.js [test] (ecmascript)"]}]);
//# sourceMappingURL=154e_minification_pure-annotated-iife-scope-hoisted_input_index_10cuajmww7lap.js.map
\ No newline at end of file
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/154e_minification_pure-annotated-iife-scope-hoisted_input_index_0z5laqz7qel98.js","[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife-scope-hoisted/input/index.js [test] (ecmascript)",t=>{"use strict";t.s(["value",()=>e],"[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife-scope-hoisted/input/index.js [test] (ecmascript)"),(0,Object.defineProperty)(function(){console.log("annotated IIFE ran")},"name",{value:"annotated",configurable:!0})();let e=1}]);
//# sourceMappingURL=154e_minification_pure-annotated-iife-scope-hoisted_input_index_0z5laqz7qel98.js.map
\ No newline at end of file
{"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife-scope-hoisted/input/name.js","turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife-scope-hoisted/input/index.js"],"sourcesContent":["var __defProp = Object.defineProperty\n\nexport var __name = (target, value) =>\n __defProp(target, 'name', { value, configurable: true })\n","import { __name } from './name.js'\n\n// The PURE annotation applies to the inner `__name(...)` call only. The outer\n// call (the IIFE) has side effects and must be kept.\n;(/* @__PURE__ */ __name(function annotated() {\n console.log('annotated IIFE ran')\n}, 'annotated'))()\n\nexport const value = 1\n"],"names":["__defProp","Object","defineProperty","__name","target","value","configurable"],"mappings":"odAGEA,ACCD,CAAC,EDJcC,OAAOC,AAGXE,ICCG,GAAG,ODJKF,AAAc,ECIZ,SAAS,EAChC,QAAQ,GAAG,CAAC,qBACd,EDHoB,OAAQ,CAAEG,MCG3B,YDHkCC,cAAc,CAAK,KCKjD,IAAM,EAAQ"}
\ No newline at end of file
var __defProp = Object.defineProperty
var __name = (target, value) =>
__defProp(target, 'name', { value, configurable: true })
// The PURE annotation applies to the inner `__name(...)` call only. The outer
// call (the IIFE) has side effects and must be kept.
;(/* @__PURE__ */ __name(function annotated() {
console.log('annotated IIFE ran')
}, 'annotated'))()
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/1ece_tests_snapshot_minification_pure-annotated-iife_input_index_0odiguvy7orvo.js",{otherChunks:["output/1jsg_tests_snapshot_minification_pure-annotated-iife_input_index_0esx4hyletpzn.js"],runtimeModuleIds:["[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife/input/index.js [test] (ecmascript)"]}]);
//# sourceMappingURL=1jsg_tests_snapshot_minification_pure-annotated-iife_input_index_0odiguvy7orvo.js.map
\ No newline at end of file
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/1jsg_tests_snapshot_minification_pure-annotated-iife_input_index_0esx4hyletpzn.js","[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife/input/index.js [test] (ecmascript)",(t,e,n)=>{(0,Object.defineProperty)(function(){console.log("annotated IIFE ran")},"name",{value:"annotated",configurable:!0})()}]);
//# sourceMappingURL=1jsg_tests_snapshot_minification_pure-annotated-iife_input_index_0esx4hyletpzn.js.map
\ No newline at end of file
{"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-iife/input/index.js"],"sourcesContent":["var __defProp = Object.defineProperty\nvar __name = (target, value) =>\n __defProp(target, 'name', { value, configurable: true })\n\n// The PURE annotation applies to the inner `__name(...)` call only. The outer\n// call (the IIFE) has side effects and must be kept.\n;(/* @__PURE__ */ __name(function annotated() {\n console.log('annotated IIFE ran')\n}, 'annotated'))()\n"],"names":["__defProp","Object","defineProperty","__name","target","value","configurable","annotated","console","log"],"mappings":"6RAEEA,AAID,CAAC,EANcC,OAAOC,AAEXE,IAIG,GAAGD,OANKD,AAAc,EAMZ,SAASK,EAChCC,QAAQC,GAAG,CAAC,qBACd,EANoB,OAAQ,CAAEJ,MAM3B,YANkCC,cAAc,CAAK"}
\ No newline at end of file
function make() {
return {
run() {
console.log('member call ran')
},
}
}
// The PURE annotation applies to the inner `make()` call only. The outer
// `.run()` call has side effects and must be kept.
;(/* @__PURE__ */ make()).run()
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/1ece_tests_snapshot_minification_pure-annotated-member_input_index_1k5u1-yl8rq5n.js",{otherChunks:["output/1jsg_tests_snapshot_minification_pure-annotated-member_input_index_06zc3vqhxqozy.js"],runtimeModuleIds:["[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-member/input/index.js [test] (ecmascript)"]}]);
//# sourceMappingURL=1jsg_tests_snapshot_minification_pure-annotated-member_input_index_1k5u1-yl8rq5n.js.map
\ No newline at end of file
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/1jsg_tests_snapshot_minification_pure-annotated-member_input_index_06zc3vqhxqozy.js","[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-member/input/index.js [test] (ecmascript)",(t,e,s)=>{({run(){console.log("member call ran")}}).run()}]);
//# sourceMappingURL=1jsg_tests_snapshot_minification_pure-annotated-member_input_index_06zc3vqhxqozy.js.map
\ No newline at end of file
{"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/minification/pure-annotated-member/input/index.js"],"sourcesContent":["function make() {\n return {\n run() {\n console.log('member call ran')\n },\n }\n}\n\n// The PURE annotation applies to the inner `make()` call only. The outer\n// `.run()` call has side effects and must be kept.\n;(/* @__PURE__ */ make()).run()\n"],"names":["make","run","console","log"],"mappings":"iSAUC,CATQ,AASP,CAREC,MACEC,MAOS,EAPDC,CAOIH,EAPD,CAAC,kBACd,EACF,EAKwBC,GAAG"}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment