forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This backports bfd1531 from react 15.2 (facebook#6882); it took some …
…help from 1d0c1b1 to get the basic gulp setup (0.14 beta v2 code), and took a lot of dependency wrangling. `grunt extract-errors` should run the script now. I'm starting with a fresh codes.json because these will never match up with the official ones unfortunately. Things skipped: - travis integration. I don't know anything about travis so don't know if / how to hook this up for it. - inserting this as part of a full build process. It looks like it's a oneoff in master too fwiw
- Loading branch information
David Goldstein
committed
Jul 2, 2016
1 parent
65c4715
commit a298281
Showing
10 changed files
with
510 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
var babel = require('gulp-babel'); | ||
var flatten = require('gulp-flatten'); | ||
var del = require('del'); | ||
|
||
var extractErrors = require('./scripts/error-codes/gulp-extract-errors'); | ||
|
||
var paths = { | ||
react: { | ||
src: [ | ||
'src/**/*.js', | ||
'!src/**/__tests__/**/*.js', | ||
'!test/all.js', | ||
], | ||
lib: 'build/modules', | ||
}, | ||
}; | ||
|
||
var errorCodeOpts = { | ||
errorMapFilePath: 'scripts/error-codes/codes.json', | ||
}; | ||
|
||
gulp.task('react:extract-errors', function() { | ||
return gulp | ||
.src(paths.react.src) | ||
.pipe(extractErrors(errorCodeOpts)); | ||
}); | ||
|
||
gulp.task('default', ['react:extract-errors']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* 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. | ||
* | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
/*:: export type ErrorMap = { [id: string]: string; }; */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
'use strict'; | ||
|
||
var evalToString = require('../evalToString'); | ||
var babylon = require('babylon'); | ||
|
||
var parse = (source) => babylon.parse( | ||
`(${source});` | ||
).program.body[0].expression; // quick way to get an exp node | ||
|
||
var parseAndEval = (source) => evalToString(parse(source)); | ||
|
||
describe('evalToString', () => { | ||
it('should support StringLiteral', () => { | ||
expect(parseAndEval(`'foobar'`)).toBe('foobar'); | ||
expect(parseAndEval(`'yowassup'`)).toBe('yowassup'); | ||
}); | ||
|
||
it('should support string concat (`+`)', () => { | ||
expect(parseAndEval(`'foo ' + 'bar'`)).toBe('foo bar'); | ||
}); | ||
|
||
it('should throw when it finds other types', () => { | ||
expect(() => parseAndEval(`'foo ' + true`)).toThrowError(/Unsupported type/); | ||
expect(() => parseAndEval(`'foo ' + 3`)).toThrowError(/Unsupported type/); | ||
expect(() => parseAndEval(`'foo ' + null`)).toThrowError(/Unsupported type/); | ||
expect(() => parseAndEval(`'foo ' + undefined`)).toThrowError(/Unsupported type/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
'use strict'; | ||
|
||
var invertObject = require('../invertObject'); | ||
|
||
var objectValues = (target) => Object.keys(target).map((key) => target[key]); | ||
|
||
describe('invertObject', () => { | ||
it('should return an empty object for an empty input', () => { | ||
expect(invertObject({})).toEqual({}); | ||
}); | ||
|
||
it('should invert key-values', () => { | ||
expect(invertObject({ | ||
a: '3', | ||
b: '4', | ||
})).toEqual({ | ||
3: 'a', | ||
4: 'b', | ||
}); | ||
}); | ||
|
||
it('should take the last value when there\'re duplications in vals', () => { | ||
expect(invertObject({ | ||
a: '3', | ||
b: '4', | ||
c: '3', | ||
})).toEqual({ | ||
4: 'b', | ||
3: 'c', | ||
}); | ||
}); | ||
|
||
it('should perserve the original order', () => { | ||
expect(Object.keys(invertObject({ | ||
a: '3', | ||
b: '4', | ||
c: '3', | ||
}))).toEqual(['3', '4']); | ||
|
||
expect(objectValues(invertObject({ | ||
a: '3', | ||
b: '4', | ||
c: '3', | ||
}))).toEqual(['c', 'b']); | ||
}); | ||
}); |
Oops, something went wrong.