mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add @format to a few files
Reviewed By: davidaurelio Differential Revision: D5111297 fbshipit-source-id: bde11df412dd694edca78d6a61f4c69e5abba60a
This commit is contained in:
committed by
Facebook Github Bot
parent
ab346dd1f9
commit
4f980eedbd
@@ -5,6 +5,8 @@
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
@@ -46,10 +48,12 @@ describe('transforming JS modules:', () => {
|
||||
it('passes through file name and code', done => {
|
||||
transformModule(sourceCode, options(), (error, result) => {
|
||||
expect(result.type).toBe('code');
|
||||
expect(result.details).toEqual(expect.objectContaining({
|
||||
code: sourceCode,
|
||||
file: filename,
|
||||
}));
|
||||
expect(result.details).toEqual(
|
||||
expect.objectContaining({
|
||||
code: sourceCode,
|
||||
file: filename,
|
||||
}),
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -73,11 +77,17 @@ describe('transforming JS modules:', () => {
|
||||
});
|
||||
|
||||
it('sets `type` to `"script"` if the input is a polyfill', done => {
|
||||
transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => {
|
||||
expect(result.type).toBe('code');
|
||||
expect(result.details).toEqual(expect.objectContaining({type: 'script'}));
|
||||
done();
|
||||
});
|
||||
transformModule(
|
||||
sourceCode,
|
||||
{...options(), polyfill: true},
|
||||
(error, result) => {
|
||||
expect(result.type).toBe('code');
|
||||
expect(result.details).toEqual(
|
||||
expect.objectContaining({type: 'script'}),
|
||||
);
|
||||
done();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const defaults = {
|
||||
@@ -89,24 +99,25 @@ describe('transforming JS modules:', () => {
|
||||
projectRoot: '',
|
||||
};
|
||||
|
||||
it('calls the passed-in transform function with code, file name, and options ' +
|
||||
'for all passed in variants',
|
||||
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({
|
||||
filename,
|
||||
localPath: filename,
|
||||
options: {...defaults, ...variants.dev},
|
||||
src: sourceCode,
|
||||
});
|
||||
filename,
|
||||
localPath: filename,
|
||||
options: {...defaults, ...variants.dev},
|
||||
src: sourceCode,
|
||||
});
|
||||
expect(transformer.transform).toBeCalledWith({
|
||||
filename,
|
||||
localPath: filename,
|
||||
options: {...defaults, ...variants.prod},
|
||||
src: sourceCode,
|
||||
});
|
||||
filename,
|
||||
localPath: filename,
|
||||
options: {...defaults, ...variants.prod},
|
||||
src: sourceCode,
|
||||
});
|
||||
done();
|
||||
});
|
||||
},
|
||||
@@ -127,24 +138,27 @@ describe('transforming JS modules:', () => {
|
||||
expect(error).toEqual(null);
|
||||
|
||||
const {code, dependencyMapName} = result.details.transformed.default;
|
||||
expect(code.replace(/\s+/g, ''))
|
||||
.toEqual(
|
||||
`__d(function(global,require,module,exports,${
|
||||
dependencyMapName}){${transformedCode}});`
|
||||
);
|
||||
expect(code.replace(/\s+/g, '')).toEqual(
|
||||
`__d(function(global,require,module,exports,${dependencyMapName}){${transformedCode}});`,
|
||||
);
|
||||
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);
|
||||
transformModule(
|
||||
sourceCode,
|
||||
{...options(), polyfill: true},
|
||||
(error, result) => {
|
||||
expect(error).toEqual(null);
|
||||
|
||||
const {code} = result.details.transformed.default;
|
||||
expect(code.replace(/\s+/g, ''))
|
||||
.toEqual(`(function(global){${transformedCode}})(this);`);
|
||||
done();
|
||||
});
|
||||
const {code} = result.details.transformed.default;
|
||||
expect(code.replace(/\s+/g, '')).toEqual(
|
||||
`(function(global){${transformedCode}})(this);`,
|
||||
);
|
||||
done();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('creates source maps', done => {
|
||||
@@ -152,8 +166,9 @@ describe('transforming JS modules:', () => {
|
||||
const {code, map} = result.details.transformed.default;
|
||||
const column = code.indexOf('code');
|
||||
const consumer = new SourceMapConsumer(map);
|
||||
expect(consumer.originalPositionFor({line: 1, column}))
|
||||
.toEqual(expect.objectContaining({line: 1, column: sourceCode.indexOf('code')}));
|
||||
expect(consumer.originalPositionFor({line: 1, column})).toEqual(
|
||||
expect.objectContaining({line: 1, column: sourceCode.indexOf('code')}),
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -166,8 +181,9 @@ describe('transforming JS modules:', () => {
|
||||
transformer.transform.stub.returns(transformResult(body));
|
||||
|
||||
transformModule(code, options(), (error, result) => {
|
||||
expect(result.details.transformed.default)
|
||||
.toEqual(expect.objectContaining({dependencies: [dep1, dep2]}));
|
||||
expect(result.details.transformed.default).toEqual(
|
||||
expect.objectContaining({dependencies: [dep1, dep2]}),
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -176,22 +192,18 @@ describe('transforming JS modules:', () => {
|
||||
const variants = {dev: {dev: true}, prod: {dev: false}};
|
||||
transformer.transform.stub
|
||||
.withArgs(filename, sourceCode, variants.dev)
|
||||
.returns(transformResult(bodyAst))
|
||||
.returns(transformResult(bodyAst))
|
||||
.withArgs(filename, sourceCode, variants.prod)
|
||||
.returns(transformResult([]));
|
||||
.returns(transformResult([]));
|
||||
|
||||
transformModule(sourceCode, options(variants), (error, result) => {
|
||||
const {dev, prod} = result.details.transformed;
|
||||
expect(dev.code.replace(/\s+/g, ''))
|
||||
.toEqual(
|
||||
`__d(function(global,require,module,exports,${
|
||||
dev.dependencyMapName}){arbitrary(code);});`
|
||||
);
|
||||
expect(prod.code.replace(/\s+/g, ''))
|
||||
.toEqual(
|
||||
`__d(function(global,require,module,exports,${
|
||||
prod.dependencyMapName}){arbitrary(code);});`
|
||||
);
|
||||
expect(dev.code.replace(/\s+/g, '')).toEqual(
|
||||
`__d(function(global,require,module,exports,${dev.dependencyMapName}){arbitrary(code);});`,
|
||||
);
|
||||
expect(prod.code.replace(/\s+/g, '')).toEqual(
|
||||
`__d(function(global,require,module,exports,${prod.dependencyMapName}){arbitrary(code);});`,
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -199,23 +211,31 @@ describe('transforming JS modules:', () => {
|
||||
it('prefixes JSON files with `module.exports = `', done => {
|
||||
const json = '{"foo":"bar"}';
|
||||
|
||||
transformModule(json, {...options(), filename: 'some.json'}, (error, result) => {
|
||||
const {code} = result.details.transformed.default;
|
||||
expect(code.replace(/\s+/g, ''))
|
||||
.toEqual(
|
||||
transformModule(
|
||||
json,
|
||||
{...options(), filename: 'some.json'},
|
||||
(error, result) => {
|
||||
const {code} = result.details.transformed.default;
|
||||
expect(code.replace(/\s+/g, '')).toEqual(
|
||||
'__d(function(global,require,module,exports){' +
|
||||
`module.exports=${json}});`
|
||||
`module.exports=${json}});`,
|
||||
);
|
||||
done();
|
||||
});
|
||||
done();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('does not create source maps for JSON files', done => {
|
||||
transformModule('{}', {...options(), filename: 'some.json'}, (error, result) => {
|
||||
expect(result.details.transformed.default)
|
||||
.toEqual(expect.objectContaining({map: null}));
|
||||
done();
|
||||
});
|
||||
transformModule(
|
||||
'{}',
|
||||
{...options(), filename: 'some.json'},
|
||||
(error, result) => {
|
||||
expect(result.details.transformed.default).toEqual(
|
||||
expect.objectContaining({map: null}),
|
||||
);
|
||||
done();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('adds package data for `package.json` files', done => {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
@@ -70,12 +71,13 @@ function transformModule(
|
||||
const {filename, transformer, variants = defaultVariants} = options;
|
||||
const tasks = {};
|
||||
Object.keys(variants).forEach(name => {
|
||||
tasks[name] = asyncify(() => transformer.transform({
|
||||
tasks[name] = asyncify(() =>
|
||||
transformer.transform({
|
||||
filename,
|
||||
localPath: filename,
|
||||
options: {...defaultTransformOptions, ...variants[name]},
|
||||
src: code,
|
||||
})
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -89,7 +91,12 @@ function transformModule(
|
||||
|
||||
//$FlowIssue #14545724
|
||||
Object.entries(results).forEach(([key, value]: [*, TransformFnResult]) => {
|
||||
transformed[key] = makeResult(value.ast, filename, code, options.polyfill);
|
||||
transformed[key] = makeResult(
|
||||
value.ast,
|
||||
filename,
|
||||
code,
|
||||
options.polyfill,
|
||||
);
|
||||
});
|
||||
|
||||
const annotations = docblock.parseAsObject(docblock.extract(code));
|
||||
@@ -112,10 +119,7 @@ function transformModule(
|
||||
function transformJSON(json, options, callback) {
|
||||
const value = JSON.parse(json);
|
||||
const {filename} = options;
|
||||
const code =
|
||||
`__d(function(${JsFileWrapping.MODULE_FACTORY_PARAMETERS.join(', ')}) { module.exports = \n${
|
||||
json
|
||||
}\n});`;
|
||||
const code = `__d(function(${JsFileWrapping.MODULE_FACTORY_PARAMETERS.join(', ')}) { module.exports = \n${json}\n});`;
|
||||
|
||||
const moduleData = {
|
||||
code,
|
||||
@@ -124,9 +128,9 @@ function transformJSON(json, options, callback) {
|
||||
};
|
||||
const transformed = {};
|
||||
|
||||
Object
|
||||
.keys(options.variants || defaultVariants)
|
||||
.forEach(key => (transformed[key] = moduleData));
|
||||
Object.keys(options.variants || defaultVariants).forEach(
|
||||
key => (transformed[key] = moduleData),
|
||||
);
|
||||
|
||||
const result: TransformedCodeFile = {
|
||||
assetContent: null,
|
||||
|
||||
Reference in New Issue
Block a user