mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-06 09:31:11 +08:00
Fix lint errors 2/2
Reviewed By: jeanlauliac Differential Revision: D4628330 fbshipit-source-id: 94fad1294e22fa0073e15843f94241ae778112a0
This commit is contained in:
committed by
Facebook Github Bot
parent
04f42ab075
commit
4d00df41b4
@@ -208,50 +208,52 @@ describe('Graph:', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('calls back with an array of modules in depth-first traversal order, regardless of the order of resolution', done => {
|
||||
load.stub.reset();
|
||||
resolve.stub.reset();
|
||||
it('resolves modules in depth-first traversal order, regardless of the order of resolution',
|
||||
done => {
|
||||
load.stub.reset();
|
||||
resolve.stub.reset();
|
||||
|
||||
const ids = [
|
||||
'a',
|
||||
'b',
|
||||
'c', 'd',
|
||||
'e',
|
||||
'f', 'g',
|
||||
'h',
|
||||
];
|
||||
ids.forEach(id => {
|
||||
const path = idToPath(id);
|
||||
resolve.stub.withArgs(id).yields(null, path);
|
||||
load.stub.withArgs(path).yields(null, createFile(id), []);
|
||||
});
|
||||
load.stub.withArgs(idToPath('a')).yields(null, createFile('a'), ['b', 'e', 'h']);
|
||||
load.stub.withArgs(idToPath('b')).yields(null, createFile('b'), ['c', 'd']);
|
||||
load.stub.withArgs(idToPath('e')).yields(null, createFile('e'), ['f', 'g']);
|
||||
const ids = [
|
||||
'a',
|
||||
'b',
|
||||
'c', 'd',
|
||||
'e',
|
||||
'f', 'g',
|
||||
'h',
|
||||
];
|
||||
ids.forEach(id => {
|
||||
const path = idToPath(id);
|
||||
resolve.stub.withArgs(id).yields(null, path);
|
||||
load.stub.withArgs(path).yields(null, createFile(id), []);
|
||||
});
|
||||
load.stub.withArgs(idToPath('a')).yields(null, createFile('a'), ['b', 'e', 'h']);
|
||||
load.stub.withArgs(idToPath('b')).yields(null, createFile('b'), ['c', 'd']);
|
||||
load.stub.withArgs(idToPath('e')).yields(null, createFile('e'), ['f', 'g']);
|
||||
|
||||
// load certain ids later
|
||||
['b', 'e', 'h'].forEach(id => resolve.stub.withArgs(id).resetBehavior());
|
||||
resolve.stub.withArgs('h').func = (a, b, c, d, callback) => {
|
||||
callback(null, idToPath('h'));
|
||||
['e', 'b'].forEach(
|
||||
id => resolve.stub.withArgs(id).yield(null, idToPath(id)));
|
||||
};
|
||||
// load certain ids later
|
||||
['b', 'e', 'h'].forEach(id => resolve.stub.withArgs(id).resetBehavior());
|
||||
resolve.stub.withArgs('h').func = (a, b, c, d, callback) => {
|
||||
callback(null, idToPath('h'));
|
||||
['e', 'b'].forEach(
|
||||
id => resolve.stub.withArgs(id).yield(null, idToPath(id)));
|
||||
};
|
||||
|
||||
graph(['a'], anyPlatform, noOpts, (error, result) => {
|
||||
expect(error).toEqual(null);
|
||||
expect(result.modules).toEqual([
|
||||
createModule('a', ['b', 'e', 'h']),
|
||||
createModule('b', ['c', 'd']),
|
||||
createModule('c'),
|
||||
createModule('d'),
|
||||
createModule('e', ['f', 'g']),
|
||||
createModule('f'),
|
||||
createModule('g'),
|
||||
createModule('h'),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
graph(['a'], anyPlatform, noOpts, (error, result) => {
|
||||
expect(error).toEqual(null);
|
||||
expect(result.modules).toEqual([
|
||||
createModule('a', ['b', 'e', 'h']),
|
||||
createModule('b', ['c', 'd']),
|
||||
createModule('c'),
|
||||
createModule('d'),
|
||||
createModule('e', ['f', 'g']),
|
||||
createModule('f'),
|
||||
createModule('g'),
|
||||
createModule('h'),
|
||||
]);
|
||||
done();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it('calls back with the resolved modules of the entry points', done => {
|
||||
load.stub.reset();
|
||||
@@ -274,7 +276,7 @@ describe('Graph:', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('calls back with the resolved modules of the entry points if one entry point is a dependency of another', done => {
|
||||
it('resolves modules for all entry points correctly if one is a dependency of another', done => {
|
||||
load.stub.reset();
|
||||
resolve.stub.reset();
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ module.exports = class HasteFS {
|
||||
}
|
||||
|
||||
closest(path: string, fileName: string): ?string {
|
||||
let {dir, root} = parse(path);
|
||||
const parsedPath = parse(path);
|
||||
const root = parsedPath.root;
|
||||
let dir = parsedPath.dir;
|
||||
do {
|
||||
const candidate = join(dir, fileName);
|
||||
if (this.files.has(candidate)) {
|
||||
@@ -63,7 +65,9 @@ module.exports = class HasteFS {
|
||||
function buildDirectorySet(files) {
|
||||
const directories = new Set();
|
||||
files.forEach(path => {
|
||||
let {dir, root} = parse(path);
|
||||
const parsedPath = parse(path);
|
||||
const root = parsedPath.root;
|
||||
let dir = parsedPath.dir;
|
||||
while (dir !== '.' && dir !== root && !directories.has(dir)) {
|
||||
directories.add(dir);
|
||||
dir = dirname(dir);
|
||||
|
||||
@@ -63,27 +63,29 @@ describe('dependency collection from ASTs:', () => {
|
||||
.toEqual(any(String));
|
||||
});
|
||||
|
||||
it('replaces all required module ID strings with array lookups and keeps the ID as second argument', () => {
|
||||
const ast = astFromCode(`
|
||||
const a = require('b/lib/a');
|
||||
const b = require(123);
|
||||
exports.do = () => require("do");
|
||||
if (!something) {
|
||||
require("setup/something");
|
||||
}
|
||||
`);
|
||||
it('replaces all required module ID strings with array lookups, keeps the ID as second argument',
|
||||
() => {
|
||||
const ast = astFromCode(`
|
||||
const a = require('b/lib/a');
|
||||
const b = require(123);
|
||||
exports.do = () => require("do");
|
||||
if (!something) {
|
||||
require("setup/something");
|
||||
}
|
||||
`);
|
||||
|
||||
const {dependencyMapName} = collectDependencies(ast);
|
||||
const {dependencyMapName} = collectDependencies(ast);
|
||||
|
||||
expect(codeFromAst(ast)).toEqual(comparableCode(`
|
||||
const a = require(${dependencyMapName}[0], 'b/lib/a');
|
||||
const b = require(123);
|
||||
exports.do = () => require(${dependencyMapName}[1], "do");
|
||||
if (!something) {
|
||||
require(${dependencyMapName}[2], "setup/something");
|
||||
}
|
||||
`));
|
||||
});
|
||||
expect(codeFromAst(ast)).toEqual(comparableCode(`
|
||||
const a = require(${dependencyMapName}[0], 'b/lib/a');
|
||||
const b = require(123);
|
||||
exports.do = () => require(${dependencyMapName}[1], "do");
|
||||
if (!something) {
|
||||
require(${dependencyMapName}[2], "setup/something");
|
||||
}
|
||||
`));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('Dependency collection from optimized ASTs:', () => {
|
||||
|
||||
@@ -94,4 +94,5 @@ function findLast(code, needle) {
|
||||
return {line: line + 1, column};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ const {parse} = require('babylon');
|
||||
const generate = require('babel-generator').default;
|
||||
const {traverse} = require('babel-core');
|
||||
|
||||
const {any, objectContaining} = jasmine;
|
||||
|
||||
describe('transforming JS modules:', () => {
|
||||
const filename = 'arbitrary';
|
||||
|
||||
@@ -47,7 +45,7 @@ describe('transforming JS modules:', () => {
|
||||
|
||||
it('passes through file name and code', done => {
|
||||
transformModule(sourceCode, options(), (error, result) => {
|
||||
expect(result).toEqual(objectContaining({
|
||||
expect(result).toEqual(expect.objectContaining({
|
||||
code: sourceCode,
|
||||
file: filename,
|
||||
}));
|
||||
@@ -59,36 +57,39 @@ describe('transforming JS modules:', () => {
|
||||
const hasteID = 'TheModule';
|
||||
const codeWithHasteID = `/** @providesModule ${hasteID} */`;
|
||||
transformModule(codeWithHasteID, options(), (error, result) => {
|
||||
expect(result).toEqual(objectContaining({hasteID}));
|
||||
expect(result).toEqual(expect.objectContaining({hasteID}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sets `type` to `"module"` by default', done => {
|
||||
transformModule(sourceCode, options(), (error, result) => {
|
||||
expect(result).toEqual(objectContaining({type: 'module'}));
|
||||
expect(result).toEqual(expect.objectContaining({type: 'module'}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sets `type` to `"script"` if the input is a polyfill', done => {
|
||||
transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => {
|
||||
expect(result).toEqual(objectContaining({type: 'script'}));
|
||||
expect(result).toEqual(expect.objectContaining({type: 'script'}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('calls the passed-in transform function with code, file name, and options for all passed in variants', done => {
|
||||
const variants = {dev: {dev: true}, prod: {dev: false}};
|
||||
it('calls the passed-in transform function with code, file name, and options ' +
|
||||
'for all passed in variants',
|
||||
done => {
|
||||
const variants = {dev: {dev: true}, prod: {dev: false}};
|
||||
|
||||
transformModule(sourceCode, options(variants), () => {
|
||||
expect(transformer.transform)
|
||||
.toBeCalledWith(sourceCode, filename, variants.dev);
|
||||
expect(transformer.transform)
|
||||
.toBeCalledWith(sourceCode, filename, variants.prod);
|
||||
done();
|
||||
});
|
||||
});
|
||||
transformModule(sourceCode, options(variants), () => {
|
||||
expect(transformer.transform)
|
||||
.toBeCalledWith(sourceCode, filename, variants.dev);
|
||||
expect(transformer.transform)
|
||||
.toBeCalledWith(sourceCode, filename, variants.prod);
|
||||
done();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it('calls back with any error yielded by the transform function', done => {
|
||||
const error = new Error();
|
||||
@@ -114,7 +115,7 @@ describe('transforming JS modules:', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('wraps the code produced by the transform function into an immediately invoked function expression for polyfills', done => {
|
||||
it('wraps the code produced by the transform function into an IIFE for polyfills', done => {
|
||||
transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => {
|
||||
expect(error).toEqual(null);
|
||||
|
||||
@@ -131,20 +132,21 @@ describe('transforming JS modules:', () => {
|
||||
const column = code.indexOf('code');
|
||||
const consumer = new SourceMapConsumer(map);
|
||||
expect(consumer.originalPositionFor({line: 1, column}))
|
||||
.toEqual(objectContaining({line: 1, column: sourceCode.indexOf('code')}));
|
||||
.toEqual(expect.objectContaining({line: 1, column: sourceCode.indexOf('code')}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('extracts dependencies (require calls)', done => {
|
||||
const dep1 = 'foo', dep2 = 'bar';
|
||||
const dep1 = 'foo';
|
||||
const dep2 = 'bar';
|
||||
const code = `require('${dep1}'),require('${dep2}')`;
|
||||
const {body} = parse(code).program;
|
||||
transformer.transform.stub.returns(transformResult(body));
|
||||
|
||||
transformModule(code, options(), (error, result) => {
|
||||
expect(result.transformed.default)
|
||||
.toEqual(objectContaining({dependencies: [dep1, dep2]}));
|
||||
.toEqual(expect.objectContaining({dependencies: [dep1, dep2]}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -190,7 +192,7 @@ describe('transforming JS modules:', () => {
|
||||
it('does not create source maps for JSON files', done => {
|
||||
transformModule('{}', {...options(), filename: 'some.json'}, (error, result) => {
|
||||
expect(result.transformed.default)
|
||||
.toEqual(objectContaining({map: null}));
|
||||
.toEqual(expect.objectContaining({map: null}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,7 +44,8 @@ function transformModule(
|
||||
callback: Callback<TransformedFile>,
|
||||
): void {
|
||||
if (options.filename.endsWith('.json')) {
|
||||
return transformJSON(code, options, callback);
|
||||
transformJSON(code, options, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
const {filename, transformer, variants = defaultVariants} = options;
|
||||
@@ -86,6 +87,7 @@ function transformModule(
|
||||
type: options.polyfill ? 'script' : 'module',
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
function transformJSON(json, options, callback) {
|
||||
|
||||
Reference in New Issue
Block a user