packager: add transform-class-properties transform

Summary: I found myself a few times wanting that transform, that makes it slightly simpler to have bound method. So I propose we add it. Not a big deal though. Note it also allows static properties with the same syntax, that is handy.

Reviewed By: davidaurelio

Differential Revision: D5051579

fbshipit-source-id: 7ebf7c709bf52a30a525550c1eda1a6a2f7b8e1e
This commit is contained in:
Jean Lauliac 2017-05-12 07:31:26 -07:00 committed by Facebook Github Bot
parent b5b443f2a5
commit aadd914f0d
3 changed files with 8 additions and 9 deletions

View File

@ -25,6 +25,7 @@ function config(onlyList) {
'syntax-trailing-function-commas',
'transform-object-rest-spread',
'transform-async-to-generator',
'transform-class-properties',
].map(pluginName => require(`babel-plugin-${pluginName}`)),
only: _only,
retainLines: true,

View File

@ -110,15 +110,15 @@ function tryResolveSync<T>(action: () => T, secondaryAction: () => T): T {
}
class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
_doesFileExist: (filePath: string) => boolean;
_doesFileExist = filePath => this._options.hasteFS.exists(filePath);
_immediateResolutionCache: {[key: string]: TModule};
_options: Options<TModule, TPackage>;
static emptyModule: string;
static EMPTY_MODULE: string = require.resolve('./assets/empty-module.js');
constructor(options: Options<TModule, TPackage>) {
this._options = options;
this._resetResolutionCache();
this._doesFileExist = filePath => this._options.hasteFS.exists(filePath);
}
_tryResolve<T>(
@ -465,7 +465,7 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
);
if (realModuleName === false) {
return this._loadAsFile(
ResolutionRequest.emptyModule,
ResolutionRequest.EMPTY_MODULE,
fromModule,
toModuleName,
);
@ -485,7 +485,7 @@ class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
// exclude
if (realModuleName === false) {
return this._loadAsFile(
ResolutionRequest.emptyModule,
ResolutionRequest.EMPTY_MODULE,
fromModule,
toModuleName,
);
@ -814,6 +814,4 @@ function getArrayLowestItem(a: Array<string>): string | void {
return lowest;
}
ResolutionRequest.emptyModule = require.resolve('./assets/empty-module.js');
module.exports = ResolutionRequest;

View File

@ -1819,7 +1819,7 @@ describe('DependencyGraph', function() {
});
it('should support browser exclude of a package ("' + fieldName + '")', function() {
ResolutionRequest.emptyModule = '/root/emptyModule.js';
ResolutionRequest.EMPTY_MODULE = '/root/emptyModule.js';
var root = '/root';
setMockFileSystem({
'root': {
@ -1885,7 +1885,7 @@ describe('DependencyGraph', function() {
});
it('should support browser exclude of a file ("' + fieldName + '")', function() {
ResolutionRequest.emptyModule = '/root/emptyModule.js';
ResolutionRequest.EMPTY_MODULE = '/root/emptyModule.js';
var root = '/root';
setMockFileSystem({