Compare commits
3 Commits
eslint-plu
...
pr33071
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eaf36e3188 | ||
|
|
9db3f8b484 | ||
|
|
06beb9f43e |
@@ -48,7 +48,7 @@ import {printIdentifier, printPlace} from '../HIR/PrintHIR';
|
|||||||
import {eachPatternOperand} from '../HIR/visitors';
|
import {eachPatternOperand} from '../HIR/visitors';
|
||||||
import {Err, Ok, Result} from '../Utils/Result';
|
import {Err, Ok, Result} from '../Utils/Result';
|
||||||
import {GuardKind} from '../Utils/RuntimeDiagnosticConstants';
|
import {GuardKind} from '../Utils/RuntimeDiagnosticConstants';
|
||||||
import {assertExhaustive} from '../Utils/utils';
|
import {assertExhaustive, hasOwnProperty} from '../Utils/utils';
|
||||||
import {buildReactiveFunction} from './BuildReactiveFunction';
|
import {buildReactiveFunction} from './BuildReactiveFunction';
|
||||||
import {SINGLE_CHILD_FBT_TAGS} from './MemoizeFbtAndMacroOperandsInSameScope';
|
import {SINGLE_CHILD_FBT_TAGS} from './MemoizeFbtAndMacroOperandsInSameScope';
|
||||||
import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors';
|
import {ReactiveFunctionVisitor, visitReactiveFunction} from './visitors';
|
||||||
@@ -374,6 +374,8 @@ function codegenReactiveFunction(
|
|||||||
const countMemoBlockVisitor = new CountMemoBlockVisitor(fn.env);
|
const countMemoBlockVisitor = new CountMemoBlockVisitor(fn.env);
|
||||||
visitReactiveFunction(fn, countMemoBlockVisitor, undefined);
|
visitReactiveFunction(fn, countMemoBlockVisitor, undefined);
|
||||||
|
|
||||||
|
setMissingLocationsToNull(body);
|
||||||
|
|
||||||
return Ok({
|
return Ok({
|
||||||
type: 'CodegenFunction',
|
type: 'CodegenFunction',
|
||||||
loc: fn.loc,
|
loc: fn.loc,
|
||||||
@@ -2665,3 +2667,38 @@ function compareScopeDeclaration(
|
|||||||
else if (aName > bName) return 1;
|
else if (aName > bName) return 1;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setMissingLocationsToNull(ast: any): void {
|
||||||
|
if (Array.isArray(ast)) {
|
||||||
|
ast.forEach(item => setMissingLocationsToNull(item));
|
||||||
|
return;
|
||||||
|
} else if (
|
||||||
|
ast == null ||
|
||||||
|
typeof ast !== 'object' ||
|
||||||
|
typeof ast['type'] !== 'string'
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ast['loc'] == null) {
|
||||||
|
ast['loc'] = {
|
||||||
|
start: {line: null, column: null, index: null},
|
||||||
|
end: {line: null, column: null, index: null},
|
||||||
|
filename: null,
|
||||||
|
identifierName: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
for (const key in ast) {
|
||||||
|
if (!hasOwnProperty(ast, key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const value = ast[key];
|
||||||
|
if (typeof value !== 'object') {
|
||||||
|
/*
|
||||||
|
* We handle this above too, but avoid extra function calls in the majority of
|
||||||
|
* cases where we're traversing an AST node's properties
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
setMissingLocationsToNull(ast[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
## Input
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// @sourceMaps
|
||||||
|
export const Button = () => {
|
||||||
|
return <button>Click me</button>;
|
||||||
|
};
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Code
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { c as _c } from "react/compiler-runtime"; // @sourceMaps
|
||||||
|
export const Button = () => {
|
||||||
|
const $ = _c(1);
|
||||||
|
let t0;
|
||||||
|
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||||
|
t0 = <button>Click me</button>;
|
||||||
|
$[0] = t0;
|
||||||
|
} else {
|
||||||
|
t0 = $[0];
|
||||||
|
}
|
||||||
|
return t0;
|
||||||
|
};
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Source Map
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"version": 3,
|
||||||
|
"names": [
|
||||||
|
"Button",
|
||||||
|
"t0"
|
||||||
|
],
|
||||||
|
"sources": [
|
||||||
|
"sourcemaps-simple.ts"
|
||||||
|
],
|
||||||
|
"sourcesContent": [
|
||||||
|
"// @sourceMaps\nexport const Button = () => {\n return <button>Click me</button>;\n};\n"
|
||||||
|
],
|
||||||
|
"mappings": "kDAAA;AACA,OAAO,MAAMA,MAAM,GAAGA,CAAA,K;SACb,OAAyB,CAAjB,QAAQ,EAAhB,MAAyB,C,qCAAzBC,EAAyB,C,CACjC",
|
||||||
|
"ignoreList": []
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Eval output
|
||||||
|
(kind: exception) Fixture not implemented
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// @sourceMaps
|
||||||
|
export const Button = () => {
|
||||||
|
return <button>Click me</button>;
|
||||||
|
};
|
||||||
@@ -306,6 +306,7 @@ export type TransformResult = {
|
|||||||
original: string;
|
original: string;
|
||||||
forget: string;
|
forget: string;
|
||||||
} | null;
|
} | null;
|
||||||
|
sourceMap: BabelCore.BabelFileResult['map'];
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function transformFixtureInput(
|
export async function transformFixtureInput(
|
||||||
@@ -331,6 +332,9 @@ export async function transformFixtureInput(
|
|||||||
// with `cwd`, which is different across machines
|
// with `cwd`, which is different across machines
|
||||||
const virtualFilepath = '/' + filename;
|
const virtualFilepath = '/' + filename;
|
||||||
|
|
||||||
|
// Check if we should emit source maps in the test fixture
|
||||||
|
const includeSourceMaps = firstLine.includes('@sourceMaps');
|
||||||
|
|
||||||
const presets =
|
const presets =
|
||||||
language === 'typescript'
|
language === 'typescript'
|
||||||
? TypescriptEvaluatorPresets
|
? TypescriptEvaluatorPresets
|
||||||
@@ -357,6 +361,7 @@ export async function transformFixtureInput(
|
|||||||
'babel-plugin-idx',
|
'babel-plugin-idx',
|
||||||
],
|
],
|
||||||
sourceType: 'module',
|
sourceType: 'module',
|
||||||
|
sourceMaps: includeSourceMaps,
|
||||||
ast: includeEvaluator,
|
ast: includeEvaluator,
|
||||||
cloneInputAst: includeEvaluator,
|
cloneInputAst: includeEvaluator,
|
||||||
configFile: false,
|
configFile: false,
|
||||||
@@ -447,6 +452,7 @@ export async function transformFixtureInput(
|
|||||||
forgetOutput,
|
forgetOutput,
|
||||||
logs: formattedLogs,
|
logs: formattedLogs,
|
||||||
evaluatorCode,
|
evaluatorCode,
|
||||||
|
sourceMap: includeSourceMaps ? forgetResult.map : null,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {BabelFileResult} from '@babel/core';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
@@ -24,6 +25,7 @@ export function writeOutputToString(
|
|||||||
evaluatorOutput: string | null,
|
evaluatorOutput: string | null,
|
||||||
logs: string | null,
|
logs: string | null,
|
||||||
errorMessage: string | null,
|
errorMessage: string | null,
|
||||||
|
sourceMap: BabelFileResult['map'] | null,
|
||||||
) {
|
) {
|
||||||
// leading newline intentional
|
// leading newline intentional
|
||||||
let result = `
|
let result = `
|
||||||
@@ -42,6 +44,14 @@ ${wrapWithTripleBackticks(compilerOutput, 'javascript')}
|
|||||||
result += '\n';
|
result += '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sourceMap != null) {
|
||||||
|
result += `
|
||||||
|
## Source Map
|
||||||
|
|
||||||
|
${wrapWithTripleBackticks(JSON.stringify(sourceMap, null, 2))}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
if (logs != null) {
|
if (logs != null) {
|
||||||
result += `
|
result += `
|
||||||
## Logs
|
## Logs
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ export async function transformFixture(
|
|||||||
sproutOutput,
|
sproutOutput,
|
||||||
compileResult?.logs ?? null,
|
compileResult?.logs ?? null,
|
||||||
error,
|
error,
|
||||||
|
compileResult?.sourceMap ?? null,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user