mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
c65ae2687c
In order to make Haste work with React's artifacts, It is important to
keep headers in this format:
```
/**
* ...
...
* ...
*/
```
For optimization purposes, Closure compiler will actually modify these
headers by removing * prefixes, which is expected.
We should pass sources to the compiler without license headers, with
these changes the current flow will be:
1. Apply top-level definitions. For UMD-bundles, for example, or
DEV-only bundles (e. g. `if (__DEV__) { ...`)
2. Apply licence headers for artifacts with sourcemaps: oss-production
and oss-profiling bundles, they don't need to preserve the header format
to comply with Haste. We need to apply these headers before passing
sources to Closure, so it can build correct mappings for sourcemaps.
3. Pass these sources to closure compiler for minification and
sourcemaps building.
4. Apply licence headers for artifacts without sourcemaps: dev bundles,
fb bundles. This way the header style will be preserved and not changed
by Closure.
DiffTrain build for [c47c306a7a](https://github.com/facebook/react/commit/c47c306a7a23d3c796b148d303764e2832da480c)
148 lines
4.1 KiB
JavaScript
148 lines
4.1 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @noflow
|
|
* @nolint
|
|
* @preventMunge
|
|
* @preserve-invariant-messages
|
|
*/
|
|
|
|
"use strict";
|
|
var perf = window.performance,
|
|
setTimeout = window.setTimeout,
|
|
scheduler = global.scheduler,
|
|
getCurrentTime = perf.now.bind(perf),
|
|
deadline = 0,
|
|
currentPriorityLevel_DEPRECATED = 3;
|
|
function runTask(priorityLevel, postTaskPriority, node, callback) {
|
|
deadline = getCurrentTime() + 5;
|
|
try {
|
|
currentPriorityLevel_DEPRECATED = priorityLevel;
|
|
var result = callback(!1);
|
|
if ("function" === typeof result) {
|
|
var continuationOptions = { signal: node._controller.signal },
|
|
nextTask = runTask.bind(
|
|
null,
|
|
priorityLevel,
|
|
postTaskPriority,
|
|
node,
|
|
result
|
|
);
|
|
void 0 !== scheduler.yield
|
|
? scheduler
|
|
.yield(continuationOptions)
|
|
.then(nextTask)
|
|
.catch(handleAbortError)
|
|
: scheduler
|
|
.postTask(nextTask, continuationOptions)
|
|
.catch(handleAbortError);
|
|
}
|
|
} catch (error) {
|
|
setTimeout(function () {
|
|
throw error;
|
|
});
|
|
} finally {
|
|
currentPriorityLevel_DEPRECATED = 3;
|
|
}
|
|
}
|
|
function handleAbortError() {}
|
|
exports.unstable_IdlePriority = 5;
|
|
exports.unstable_ImmediatePriority = 1;
|
|
exports.unstable_LowPriority = 4;
|
|
exports.unstable_NormalPriority = 3;
|
|
exports.unstable_Profiling = null;
|
|
exports.unstable_UserBlockingPriority = 2;
|
|
exports.unstable_cancelCallback = function (node) {
|
|
node._controller.abort();
|
|
};
|
|
exports.unstable_continueExecution = function () {};
|
|
exports.unstable_forceFrameRate = function () {};
|
|
exports.unstable_getCurrentPriorityLevel = function () {
|
|
return currentPriorityLevel_DEPRECATED;
|
|
};
|
|
exports.unstable_getFirstCallbackNode = function () {
|
|
return null;
|
|
};
|
|
exports.unstable_next = function (callback) {
|
|
switch (currentPriorityLevel_DEPRECATED) {
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
var priorityLevel = 3;
|
|
break;
|
|
default:
|
|
priorityLevel = currentPriorityLevel_DEPRECATED;
|
|
}
|
|
var previousPriorityLevel = currentPriorityLevel_DEPRECATED;
|
|
currentPriorityLevel_DEPRECATED = priorityLevel;
|
|
try {
|
|
return callback();
|
|
} finally {
|
|
currentPriorityLevel_DEPRECATED = previousPriorityLevel;
|
|
}
|
|
};
|
|
exports.unstable_now = getCurrentTime;
|
|
exports.unstable_pauseExecution = function () {};
|
|
exports.unstable_requestPaint = function () {};
|
|
exports.unstable_runWithPriority = function (priorityLevel, callback) {
|
|
var previousPriorityLevel = currentPriorityLevel_DEPRECATED;
|
|
currentPriorityLevel_DEPRECATED = priorityLevel;
|
|
try {
|
|
return callback();
|
|
} finally {
|
|
currentPriorityLevel_DEPRECATED = previousPriorityLevel;
|
|
}
|
|
};
|
|
exports.unstable_scheduleCallback = function (
|
|
priorityLevel,
|
|
callback,
|
|
options
|
|
) {
|
|
switch (priorityLevel) {
|
|
case 1:
|
|
case 2:
|
|
var postTaskPriority = "user-blocking";
|
|
break;
|
|
case 4:
|
|
case 3:
|
|
postTaskPriority = "user-visible";
|
|
break;
|
|
case 5:
|
|
postTaskPriority = "background";
|
|
break;
|
|
default:
|
|
postTaskPriority = "user-visible";
|
|
}
|
|
var controller = new TaskController({ priority: postTaskPriority });
|
|
options = {
|
|
delay: "object" === typeof options && null !== options ? options.delay : 0,
|
|
signal: controller.signal
|
|
};
|
|
controller = { _controller: controller };
|
|
scheduler
|
|
.postTask(
|
|
runTask.bind(null, priorityLevel, postTaskPriority, controller, callback),
|
|
options
|
|
)
|
|
.catch(handleAbortError);
|
|
return controller;
|
|
};
|
|
exports.unstable_shouldYield = function () {
|
|
return getCurrentTime() >= deadline;
|
|
};
|
|
exports.unstable_wrapCallback = function (callback) {
|
|
var parentPriorityLevel = currentPriorityLevel_DEPRECATED;
|
|
return function () {
|
|
var previousPriorityLevel = currentPriorityLevel_DEPRECATED;
|
|
currentPriorityLevel_DEPRECATED = parentPriorityLevel;
|
|
try {
|
|
return callback();
|
|
} finally {
|
|
currentPriorityLevel_DEPRECATED = previousPriorityLevel;
|
|
}
|
|
};
|
|
};
|