Skip to content

Commit

Permalink
Fix module-boundary wrappers (facebook#22688)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored and KamranAsif committed Nov 4, 2021
1 parent f8bc548 commit d783a62
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
32 changes: 18 additions & 14 deletions scripts/rollup/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ const {

const {RECONCILER} = moduleTypes;

const USE_STRICT_HEADER_REGEX = /'use strict';\n+/;

function registerInternalModuleStart(globalName) {
const path = resolve(
__dirname,
'..',
'..',
'packages/shared/registerInternalModuleStart.js'
);
return String(readFileSync(path)).trim();
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleBegin.js');
const file = readFileSync(path);
return String(file).trim();
}

function registerInternalModuleStop(globalName) {
const path = resolve(
__dirname,
'..',
'..',
'packages/shared/registerInternalModuleStop.js'
);
return String(readFileSync(path)).trim();
const path = resolve(__dirname, 'wrappers', 'registerInternalModuleEnd.js');
const file = readFileSync(path);

// Remove the 'use strict' directive from the footer.
// This directive is only meaningful when it is the first statement in a file or function.
return String(file)
.replace(USE_STRICT_HEADER_REGEX, '')
.trim();
}

const license = ` * Copyright (c) Facebook, Inc. and its affiliates.
Expand Down Expand Up @@ -359,6 +358,11 @@ function wrapBundle(
case RN_OSS_PROFILING:
case RN_FB_DEV:
case RN_FB_PROFILING:
// Remove the 'use strict' directive from source.
// The module start wrapper will add its own.
// This directive is only meaningful when it is the first statement in a file or function.
source = source.replace(USE_STRICT_HEADER_REGEX, '');

// Certain DEV and Profiling bundles should self-register their own module boundaries with DevTools.
// This allows the Timeline to de-emphasize (dim) internal stack frames.
source = `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */

// Don't require this file directly; it's embedded by Rollup during build.

if (
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */

// Don't require this file directly; it's embedded by Rollup during build.

if (
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
Expand Down

0 comments on commit d783a62

Please sign in to comment.