Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module-boundary wrappers #22688

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Scheduling Profiler 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