Skip to content

Commit 8ca3f56

Browse files
author
Brian Vaughn
authored
Fix module-boundary wrappers (#22688)
1 parent 1bf6deb commit 8ca3f56

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed

Diff for: scripts/rollup/wrappers.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,23 @@ const {
2727

2828
const {RECONCILER} = moduleTypes;
2929

30+
const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;
31+
3032
function registerInternalModuleStart(globalName) {
31-
const path = resolve(
32-
__dirname,
33-
'..',
34-
'..',
35-
'packages/shared/registerInternalModuleStart.js'
36-
);
37-
return String(readFileSync(path)).trim();
33+
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js');
34+
const file = readFileSync(path);
35+
return String(file).trim();
3836
}
3937

4038
function registerInternalModuleStop(globalName) {
41-
const path = resolve(
42-
__dirname,
43-
'..',
44-
'..',
45-
'packages/shared/registerInternalModuleStop.js'
46-
);
47-
return String(readFileSync(path)).trim();
39+
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleEnd.js');
40+
const file = readFileSync(path);
41+
42+
// Remove the 'use strict' directive from the footer.
43+
// This directive is only meaningful when it is the first statement in a file or function.
44+
return String(file)
45+
.replace(USE_STRICT_HEADER_REGEX, '')
46+
.trim();
4847
}
4948

5049
const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
@@ -359,6 +358,11 @@ function wrapBundle(
359358
case RN_OSS_PROFILING:
360359
case RN_FB_DEV:
361360
case RN_FB_PROFILING:
361+
// Remove the 'use strict' directive from source.
362+
// The module start wrapper will add its own.
363+
// This directive is only meaningful when it is the first statement in a file or function.
364+
source = source.replace(USE_STRICT_HEADER_REGEX, '');
365+
362366
// Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
363367
// This allows the Timeline to de-emphasize (dim) internal stack frames.
364368
source = `

Diff for: packages/shared/registerInternalModuleStart.js renamed to scripts/rollup/wrappers/registerInternalModuleBegin.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
3-
*
4-
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
6-
*/
1+
'use strict';
72

83
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
9-
10-
// Don't require this file directly; it's embedded by Rollup during build.
11-
124
if (
135
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
146
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===

Diff for: packages/shared/registerInternalModuleStop.js renamed to scripts/rollup/wrappers/registerInternalModuleEnd.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
3-
*
4-
* This source code is licensed under the MIT license found in the
5-
* LICENSE file in the root directory of this source tree.
6-
*/
1+
'use strict';
72

83
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
9-
10-
// Don't require this file directly; it's embedded by Rollup during build.
11-
124
if (
135
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
146
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===

0 commit comments

Comments
 (0)