Permalink
Browse files

Fix lint errors 2/2

Reviewed By: jeanlauliac

Differential Revision: D4628330

fbshipit-source-id: 94fad1294e22fa0073e15843f94241ae778112a0
  • Loading branch information...
cpojer authored and facebook-github-bot committed Mar 1, 2017
1 parent 04f42ab commit 4d00df41b451e5223ac75e6914454b7e44105aa4
View
@@ -29,7 +29,7 @@ function escapeRegExp(pattern) {
} else if (typeof pattern === 'string') {
var escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
// convert the '/' into an escaped local file separator
return escaped.replace(/\//g,'\\' + path.sep);
return escaped.replace(/\//g, '\\' + path.sep);
} else {
throw new Error('Unexpected packager blacklist pattern: ' + pattern);
}
@@ -12,7 +12,6 @@ jest.disableAutomock();
const Bundle = require('../Bundle');
const ModuleTransport = require('../../lib/ModuleTransport');
const SourceMapGenerator = require('source-map').SourceMapGenerator;
const crypto = require('crypto');
describe('Bundle', () => {
@@ -107,33 +106,37 @@ describe('Bundle', () => {
});
});
it('should insert modules in a deterministic order, independent from timing of the wrapping process', () => {
const moduleTransports = [
createModuleTransport({name: 'module1'}),
createModuleTransport({name: 'module2'}),
createModuleTransport({name: 'module3'}),
];
const resolves = {};
const resolver = {
wrapModule({name}) {
return new Promise(resolve => resolves[name] = resolve);
},
};
const promise = Promise.all(
moduleTransports.map(m => bundle.addModule(resolver, null, {isPolyfill: () => false}, m)))
.then(() => {
expect(bundle.getModules())
.toEqual(moduleTransports);
});
it('inserts modules in a deterministic order, independent of timing of the wrapper process',
() => {
const moduleTransports = [
createModuleTransport({name: 'module1'}),
createModuleTransport({name: 'module2'}),
createModuleTransport({name: 'module3'}),
];
const resolves = {};
const resolver = {
wrapModule({name}) {
return new Promise(resolve => {
resolves[name] = resolve;
});
},
};
const promise = Promise.all(moduleTransports.map(
m => bundle.addModule(resolver, null, {isPolyfill: () => false}, m)
)).then(() => {
expect(bundle.getModules())
.toEqual(moduleTransports);
});
resolves.module2({code: ''});
resolves.module3({code: ''});
resolves.module1({code: ''});
resolves.module2({code: ''});
resolves.module3({code: ''});
resolves.module1({code: ''});
return promise;
});
return promise;
},
);
});
describe('sourcemap bundle', () => {
@@ -268,7 +271,6 @@ describe('Bundle', () => {
describe('getEtag()', function() {
it('should return an etag', function() {
var bundle = new Bundle({sourceMapUrl: 'test_url'});
bundle.finalize({});
var eTag = crypto.createHash('md5').update(bundle.getSource()).digest('hex');
expect(bundle.getEtag()).toEqual(eTag);
@@ -38,7 +38,10 @@ const VERSION = require('../../package.json').version;
import type AssetServer from '../AssetServer';
import type Module, {HasteImpl} from '../node-haste/Module';
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
import type {Options as JSTransformerOptions, TransformOptions} from '../JSTransformer/worker/worker';
import type {
Options as JSTransformerOptions,
TransformOptions,
} from '../JSTransformer/worker/worker';
import type {Reporter} from '../lib/reporting';
import type GlobalTransformCache from '../lib/GlobalTransformCache';
@@ -8,13 +8,14 @@
*
* @flow
*/
/**
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
*
* Based on the Base 64 VLQ implementation in Closure Compiler:
* https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
* https://git.io/vymuA
*
* Copyright 2011 The Closure Compiler Authors. All rights reserved.
* Redistribution and use in source and binary forms, with or without
@@ -107,7 +108,8 @@ function toVLQSigned(value) {
* V8 OPTIMIZATION!
*/
function encode(value: number, buffer: Buffer, position: number): number {
let digit, vlq = toVLQSigned(value);
let vlq = toVLQSigned(value);
let digit;
do {
digit = vlq & VLQ_BASE_MASK;
vlq >>>= VLQ_BASE_SHIFT;
@@ -8,6 +8,8 @@
*/
'use strict';
/* eslint-disable max-len */
jest.disableAutomock();
const inline = require('../inline');
const {transform, transformFromAst} = require('babel-core');
@@ -205,7 +207,9 @@ describe('inline constants', () => {
var b = a.ReactNative.Platform.select({});
}`;
const {ast} = inline('arbitrary.js', {code}, {platform: 'ios'});
expect(toString(ast)).toEqual(normalize(code.replace(/ReactNative\.Platform\.select[^;]+/, '1')));
expect(toString(ast)).toEqual(
normalize(code.replace(/ReactNative\.Platform\.select[^;]+/, '1')),
);
});
it('replaces React.Platform.select in the code if React is a top level import', () => {
@@ -237,7 +241,9 @@ describe('inline constants', () => {
var b = a.ReactNative.Platform.select;
}`;
const {ast} = inline('arbitrary.js', {code}, {platform: 'android'});
expect(toString(ast)).toEqual(normalize(code.replace(/ReactNative.Platform\.select[^;]+/, '2')));
expect(toString(ast)).toEqual(
normalize(code.replace(/ReactNative.Platform\.select[^;]+/, '2')),
);
});
it('replaces require("react-native").Platform.select in the code', () => {
@@ -269,18 +275,6 @@ describe('inline constants', () => {
normalize(code.replace(/process\.env\.NODE_ENV/, '"production"')));
});
it('replaces process.env.NODE_ENV in the code', () => {
const code = `function a() {
if (process.env.NODE_ENV === 'production') {
return require('Prod');
}
return require('Dev');
}`;
const {ast} = inline('arbitrary.js', {code}, {dev: true});
expect(toString(ast)).toEqual(
normalize(code.replace(/process\.env\.NODE_ENV/, '"development"')));
});
it('accepts an AST as input', function() {
const code = 'function ifDev(a,b){return __DEV__?a:b;}';
const {ast} = inline('arbitrary.hs', {ast: toAst(code)}, {dev: false});
@@ -33,7 +33,12 @@ function extractDependencies(code: string) {
const node = path.node;
const callee = node.callee;
const arg = node.arguments[0];
if (callee.type !== 'Identifier' || callee.name !== 'require' || !arg || arg.type !== 'StringLiteral') {
if (
callee.type !== 'Identifier' ||
callee.name !== 'require' ||
!arg ||
arg.type !== 'StringLiteral'
) {
return;
}
dependencyOffsets.push(arg.start);
@@ -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();
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)));
};
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('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']);
// 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();
});
},
);
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");
}
`);
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");
}
`));
});
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);
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;
}
Oops, something went wrong.

0 comments on commit 4d00df4

Please sign in to comment.