Socket
Socket
Sign inDemoInstall

jstransform

Package Overview
Dependencies
30
Maintainers
4
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 10.1.0 to 11.0.0

bin/jstransform

9

jestEnvironment.js

@@ -0,1 +1,10 @@

/**
* Copyright 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.
*/
require.requireActual('./polyfill/Object.es6.js');

@@ -0,1 +1,10 @@

/**
* Copyright 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.
*/
var jstransform = require('./src/jstransform');

@@ -2,0 +11,0 @@ var arrowFuncVisitors = require('./visitors/es6-arrow-function-visitors');

22

package.json
{
"name": "jstransform",
"version": "10.1.0",
"version": "11.0.0",
"description": "A simple AST visitor-based JS transformer",

@@ -11,2 +11,3 @@ "contributors": [

],
"bin": "bin/jstransform",
"main": "src/jstransform",

@@ -24,12 +25,9 @@ "repository": {

"dependencies": {
"base62": "0.1.1",
"esprima-fb": "13001.1001.0-dev-harmony-fb",
"source-map": "0.1.31"
"base62": "^1.1.0",
"commoner": "^0.10.1",
"esprima-fb": "^15001.1.0-dev-harmony-fb",
"object-assign": "^2.0.0",
"source-map": "^0.4.2"
},
"licenses": [
{
"type": "Apache-2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
],
"license": "BSD-3-Clause",
"engines": {

@@ -39,4 +37,4 @@ "node": ">=0.8.8"

"devDependencies": {
"jest-cli": "^0.2",
"jshint": "^2.5.10"
"jest-cli": "^0.4.0",
"jshint": "^2.6.3"
},

@@ -43,0 +41,0 @@ "jest": {

/**
* Copyright 2014 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 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.
* @provides Object.es6

@@ -17,0 +9,0 @@ * @polyfill

@@ -11,6 +11,134 @@ # JSTransform [![Build Status](https://travis-ci.org/facebook/jstransform.svg?branch=master)](https://travis-ci.org/facebook/jstransform)

NOTE: If you're looking for a library for writing new greenfield JS transformations, consider looking at the [Recast](https://github.com/benjamn/recast) library instead of jstransform. We are still actively supporting jstransform (and intend to for the foreseeable future), but longer term we would like to direct efforts toward Recast. Recast does a far better job of supporting a multi-pass JS transformation pipeline, and this is important when attempting to apply many transformations to a source file.
- - -
**Note:**
If you're looking for a library for writing new greenfield JS transformations, consider looking at [Babel](https://github.com/babel/babel) or [Recast](https://github.com/benjamn/recast) instead of jstransform. We are still supporting jstransform (and intend to for a little while), but longer term we would like to direct efforts toward other open source projects that do a far better job of supporting a multi-pass JS transformation pipeline. This is important when attempting to apply many transformations to a source file. jstransform does a single pass resulting in performance benefits, but the tradeoff is that many transformations are much harder to write.
- - -
## Usage
### Advanced API
```js
var jstranform = require('jstransform')
```
This is the API that jstransform has always supported. It gives very fine control over the transforms you use and what order they are run in. It also allows the use of custom transforms.
#### `jstransform.transform(visitors, code, options={})`
**`visitors`**
Array of visitors. See [the React JSX visitors](https://github.com/facebook/jstransform/blob/master/visitors/react-jsx-visitors.js) as an example of what a visitor looks like.
**`code`**
String of code to be transformed.
**`options`**
Object with options that will be passed through to esprima and transforms.
#### `jstransform.Syntax`
This is the `Syntax` object re-exported from `esprima`. This is available because visitors will need access to this in order to effectively write transforms. By re-exporting we avoid the problem of conflicting versions of esprima being used.
### Simple API
```js
var simple = require('jstransform/simple')
```
The simple API was added to mirror the new command line interface. It works similarly to how `react-tools` worked - there is no need to know exactly which transforms to run. Instead transforms are selected automatically based on the options.
#### `simple.transform(code, options={})`
**`code`**
String of code to be transformed.
**`options`**
Object with options. Available options are:
option | values | default
-------|--------|--------
`react` | `true`: enable React transforms (JSX, displayName) | `false`
`es6` | `true`: enable ES6 transforms | `false`
`es7` | `true`: enable ES7 transforms | `false`
`harmony` | `true`: shortcut to enable ES6 & ES7 transforms | `false`
`utility` | `true`: enable utility transforms (trailing commas in objects, arrays) | `false`
`target` | `es3`: generate ES3 compatible code<br>`es5`: generate ES5 compatible code | `es5`
`stripTypes` | `true`: strips out Flow type annotations | `false`
`sourceMap` | `true`: generate and return a Source Map | `false`
`sourceMapInline` | `true`: append inline source map at the end of the transformed source | `false`
`sourceFilename` | the output filename for the source map | `"source.js"`
`es6module` | `true`: parses the file as an ES6 module | `false`
`nonStrictEs6module` | `true`: parses the file as an ES6 module, except disables implicit strict-mode (i.e. CommonJS modules et al are allowed) | `false`
*Returns:* An Object with the following:
**`code`**: the transformed code
**`sourceMap`**: the source map object or `null`
#### `simple.transformFile(file, options={}, callback)`
**`file`**
String of path to a file to transform. Will be passed directly to `fs.readFile`.
**`options`**
See `transform` API.
**`callback`**
Function to call with the result, where `result` is return value of `transform`.
```js
callback(err, result)
```
#### `simple.transformFileSync(file, options={})`
The same as `transformFile` but the file is read synchronously.
### CLI
JSTransform now ships with a CLI. It was taken from the `react-tools` CLI so should be very familiar.
```sh
% jstransform --help
Usage: jstransform [options] <source directory> <output directory> [<module ID> [<module ID> ...]]
Options:
-h, --help output usage information
-V, --version output the version number
-c, --config [file] JSON configuration file (no file or - means STDIN)
-w, --watch Continually rebuild
-x, --extension <js | coffee | ...> File extension to assume when resolving module identifiers
--relativize Rewrite all module identifiers to be relative
--follow-requires Scan modules for required dependencies
--use-provides-module Respect @providesModules pragma in files
--cache-dir <directory> Alternate directory to use for disk cache
--no-cache-dir Disable the disk cache
--source-charset <utf8 | win1252 | ...> Charset of source (default: utf8)
--output-charset <utf8 | win1252 | ...> Charset of output (default: utf8)
--react Turns on the React JSX and React displayName transforms
--es6 Turns on available ES6 transforms
--es7 Turns on available ES7 transforms
--harmony Shorthand to enable all ES6 and ES7 transforms
--utility Turns on available utility transforms
--target [version] Specify your target version of ECMAScript. Valid values are "es3" and "es5". The default is "es5". "es3" will avoid uses of defineProperty and will quote reserved words. WARNING: "es5" is not properly supported, even with the use of es5shim, es5sham. If you need to support IE8, use "es3".
--strip-types Strips out type annotations.
--es6module Parses the file as a valid ES6 module. (Note that this means implicit strict mode)
--non-strict-es6module Parses the file as an ES6 module, except disables implicit strict-mode. (This is useful if you're porting non-ES6 modules to ES6, but haven't yet verified that they are strict-mode safe yet)
--source-map-inline Embed inline sourcemap in transformed source
--source-filename Filename to use when generating the inline sourcemap. Will default to filename when processing files
```
## Examples
Using a pre-bundled or existing transform:
### Advanced API
#### Using a pre-bundled or existing transform:
```js

@@ -36,3 +164,4 @@ /**

Using multiple pre-bundled or existing transforms at once:
#### Using multiple pre-bundled or existing transforms at once:
```js

@@ -61,3 +190,4 @@ /**

Writing a simple custom transform:
#### Writing a simple custom transform:
```js

@@ -102,1 +232,38 @@ /**

```
### Simple API
#### Reading a file and applying tranforms
```js
var simple = require('jstransform/simple');
var fs = require('fs');
var originalCode = fs.readFileSync('path/to/file.js');
// Apply all available ES6 transforms
var transformed = simple.transform(originalCode, {es6: true});
console.log(transformed.code);
// Apply ES6 and ES7, generating ES3 compatible code (for IE8)
transformed = simple.transform(originalCode, {harmony: true, target: 'es3'});
console.log(transformed.code);
```
## Migration Guide
### Simple API
If you are coming from `react-tools` and using Node, the APIs are very similar. There are a couple important differences.
1. JSX will not be tranformed by default! You must specify `react: true` in the options.
2. The return value of `transform` is not the same. `react-tools.transform` only returned the resulting code. `simple.transform` always returns and object with a `code` property. However, if you were using `react-tools.transformWithDetails`, `simple.transform` is essentially the same.
### CLI
These are virtually identical but again, there are some important difference.
1. JSX will not be transformed by default! You must specify `--react`.
2. We are using a different executable - `jstransform` - (`jsx` doesn't make sense here).
3. There are a numbr of new options available. Namely `--utility`, `--es6` and `--es7` (`--harmony` is still available and will enable both).
/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 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.
* @emails jeffmo@fb.com

@@ -17,0 +9,0 @@ */

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 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.
* @emails jeffmo@fb.com

@@ -17,0 +9,0 @@ */

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @emails dmitrys@fb.com

@@ -237,4 +228,10 @@ */

);
// Binds this for arrows containing <this />
expectTransform(
'(() => <this />)',
'((function() {return <this />;}.bind(this)))'
);
});
});
/**
* @emails sema@fb.com
* Copyright 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.
*
* @emails dmitrys@fb.com
*/

@@ -34,5 +41,5 @@

it('should default to null context', function() {
it('should default to undefined context', function() {
expect(transform('max(1, 2, ...list)'))
.toEqual('max.apply(null, [1, 2].concat(list))');
.toEqual('max.apply(undefined, [1, 2].concat(list))');
});

@@ -47,3 +54,3 @@

expect(transform('(function(a, b, c) { return a+b+c; })(1, 2, ...more)'))
.toEqual('(function(a, b, c) { return a+b+c; }).apply(null, [1, 2].concat(more))');
.toEqual('(function(a, b, c) { return a+b+c; }).apply(undefined, [1, 2].concat(more))');
});

@@ -50,0 +57,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @emails jeffmo@fb.com

@@ -1254,2 +1247,33 @@ */

});
it('properly handles computed static methods', function() {
var code = transform([
'var bar = "foobar";',
'class Foo {',
' static [bar]() {',
' return 42;',
' }',
'}'
].join('\n'));
eval(code);
expect(Foo.foobar()).toBe(42);
});
it('properly handles computed instance methods', function() {
var code = transform([
'var bar = "foobar";',
'class Foo {',
' [bar]() {',
' return 42;',
' }',
'}'
].join('\n'));
eval(code);
var fooInst = new Foo();
expect(fooInst.foobar()).toBe(42);
});
});

@@ -1256,0 +1280,0 @@ });

/**
* Copyright 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.
*
* @emails dmitrys@fb.com

@@ -222,2 +229,16 @@ */

it('should work with arrows without other arguments', function() {
var code = transform([
'var foo = ({x, y}) => x + y;',
'var bar = ([x, y]) => x + y;'
].join('\n'));
eval(code);
expect(foo({x: 10, y: 20}))
.toEqual(30);
expect(bar([10, 20]))
.toEqual(30);
});
// Auto-generated temp vars test.

@@ -224,0 +245,0 @@ it('should allocate correct temp index', function() {

/**
* Copyright 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.
*
* @emails sema@fb.com javascript@lists.facebook.com

@@ -3,0 +10,0 @@ */

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @emails dmitrys@fb.com

@@ -117,8 +108,2 @@ */

);
// Dynamic properties
expectTransform(
'var foo = {*[a+b](x) {yield x;}}',
'var foo = {[a+b]:function*(x) {yield x;}}'
);
});

@@ -125,0 +110,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @emails dmitrys@fb.com

@@ -19,0 +10,0 @@ */

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @emails dmitrys@fb.com

@@ -38,2 +29,3 @@ */

restParamVisitors = require('../es6-rest-param-visitors').visitorList;
callSpreadVisitors = require('../es6-call-spread-visitors').visitorList;
transformFn = require('../../src/jstransform').transform;

@@ -44,3 +36,4 @@

.concat(classVisitors)
.concat(restParamVisitors);
.concat(restParamVisitors)
.concat(callSpreadVisitors);
});

@@ -129,2 +122,18 @@

});
it('should work with temp var injections', () => {
// Use call spread as example. It injects a temp var into function scope.
var code = transform([
'function test(bar, ...args) {',
' return bar(...args);',
'}'
].join('\n'));
eval(code);
var fn = function() {
return Array.prototype.slice.call(arguments).map(i => i + 1);
};
expect(test(fn, 1, 2, 3)).toEqual([2, 3, 4]);
});
});

@@ -131,0 +140,0 @@

/**
* Copyright 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.
*
* @emails mroch@fb.com

@@ -88,5 +95,5 @@ */

expectTransform('`foo ${bar}`', '("foo " + bar)');
expectTransform('`${foo} bar`', '(foo + " bar")');
expectTransform('`${foo} ${bar}`', '(foo + " " + bar)');
expectTransform('`${foo}${bar}`', '(foo + bar)');
expectTransform('`${foo} bar`', '("" + foo + " bar")');
expectTransform('`${foo} ${bar}`', '("" + foo + " " + bar)');
expectTransform('`${foo}${bar}`', '("" + foo + bar)');
});

@@ -98,7 +105,8 @@

expectTransform('`foo ${bar + 5}`', '("foo " + (bar + 5))');
expectTransform('`${foo + 5} bar`', '((foo + 5) + " bar")');
expectTransform('`${foo + 5} ${bar}`', '((foo + 5) + " " + bar)');
expectTransform('`${foo + 5} bar`', '("" + (foo + 5) + " bar")');
expectTransform('`${foo + 5} ${bar}`', '("" + (foo + 5) + " " + bar)');
expectTransform(
'`${(function(b) {alert(4);})(a)}`',
'((function(b) {alert(4);})(a))');
'("" + (function(b) {alert(4);})(a))');
expectTransform("`${4 + 5}`", '("" + (4 + 5))');
});

@@ -190,2 +198,27 @@

it('should handle numeric expressions', function() {
expectEval("`foo${1}bar${2}`", 'foo1bar2');
expectEval("`foo${1}${2}bar`", 'foo12bar');
expectEval("`${1}${2}foo`", '12foo');
expectEval("`${1}${2}`", '12');
});
it('should handle primitive literals', function() {
expectTransform("`${42}`", '("" + 42)');
expectEval("`${42}`", '42');
expectTransform("`${'42'}`", '("" + \'42\')');
expectEval("`${'42'}`", '42');
expectTransform("`${true}`", '("" + true)');
expectEval("`${true}`", 'true');
expectTransform("`${null}`", '("" + null)');
expectEval("`${null}`", 'null');
// undefined is actually an Identifier but it falls into the same category
expectTransform("`${undefined}`", '("" + undefined)');
expectEval("`${undefined}`", 'undefined');
}),
it('should canonicalize line endings', function() {

@@ -192,0 +225,0 @@ // TODO: should this be '("foo\\nbar"\r\n)' to maintain the number of lines

/**
* Copyright 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.
*
* @emails sema@fb.com

@@ -3,0 +10,0 @@ */

/**
* Copyright 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.
*
* @emails sema@fb.com

@@ -3,0 +10,0 @@ */

@@ -1,52 +0,56 @@

/*jshint evil:true*/
/**
* Copyright 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.
*/
var tests = require("./../type-syntax-test");
/*jshint evil:true, multistr:true*/
var tests = require('./../type-syntax-test');
var jstransform = require('../../../src/jstransform');
var visitors = require('../../type-syntax').visitorList;
var fs = require("fs");
var fs = require('fs');
var out = "/*\n";
out += "* WARNING: This file is autogenerated by visitors/__tests__/gen/generate-type-syntax-test.js\n";
out += "* Do NOT modify this file directly! Instead, add your tests to \n";
out += "* visitors/__tests__/type-syntax-test.js and run visitors/__tests__/gen/generate-type-syntax-test.js\n";
out += "*/\n\n";
var out = '/**\n\
* WARNING: This file is autogenerated by\n\
* src/visitors/flow/__tests__/gen/generate-type-syntax-test.js\n\
* Do NOT modify this file directly! Instead, add your tests to\n\
* src/visitors/flow/__tests__/type-syntax-test.js and run\n\
* src/visitors/flow/__tests__/gen/generate-type-syntax-test.js\n\
*/\n\n';
function escape_content(content) {
return content
.replace(/[\\]/g, '\\\\')
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, '\\t')
.replace(/[']/g, "\\'");
}
out += "module.exports = {\n";
for (var section in tests) {
out += " '"+section+"': {\n";
for (var test in tests[section]) {
test = tests[section][test];
out += " '"+escape_content(test)+"': {\n";
var data = {};
Object.keys(tests).forEach(function(sectionName) {
var section = tests[sectionName];
var sectionData = {};
section.forEach(function(testCode) {
var code;
sectionData[testCode] = {};
var testData = {};
try {
var transformed = jstransform.transform(visitors, test).code;
out += " raworiginal: '"+escape_content(test)+"',\n";
out += " transformed: '"+escape_content(transformed)+"',\n";
code = jstransform.transform(visitors, testCode).code;
testData.raworiginal = testCode;
testData.transformed = code;
try {
eval(transformed);
out += " eval: 'No error',\n";
eval(code);
testData.eval = 'No error';
} catch (e) {
out += " eval: '"+e.message+"',\n";
testData.eval = e.message;
}
} catch (e) {
out += " error: '"+e.message+"',\n";
testData.error = e.message;
}
out += "\n";
out += " },\n";
}
out += " },\n";
}
out += "};\n";
sectionData[testCode] = testData;
});
data[sectionName] = sectionData;
});
fs.writeFileSync(__dirname+'/type-syntax-test.rec.js', out);
console.log("Recorded type-syntax-test.js output into type-syntax-test.rec.js");
out += 'module.exports = ' + JSON.stringify(data, null, 2) + ';\n';
fs.writeFileSync(__dirname + '/type-syntax-test.rec.js', out);
console.log('Recorded type-syntax-test.js output into type-syntax-test.rec.js');

@@ -1,846 +0,712 @@

/*
* WARNING: This file is autogenerated by visitors/__tests__/gen/generate-type-syntax-test.js
* Do NOT modify this file directly! Instead, add your tests to
* visitors/__tests__/type-syntax-test.js and run visitors/__tests__/gen/generate-type-syntax-test.js
*/
/**
* WARNING: This file is autogenerated by
* src/visitors/flow/__tests__/gen/generate-type-syntax-test.js
* Do NOT modify this file directly! Instead, add your tests to
* src/visitors/flow/__tests__/type-syntax-test.js and run
* src/visitors/flow/__tests__/gen/generate-type-syntax-test.js
*/
module.exports = {
'TypeAnnotations': {
'function foo(numVal: any){}': {
raworiginal: 'function foo(numVal: any){}',
transformed: 'function foo(numVal ){}',
eval: 'No error',
},
'function foo(numVal: number){}': {
raworiginal: 'function foo(numVal: number){}',
transformed: 'function foo(numVal ){}',
eval: 'No error',
},
'function foo(numVal: number, strVal: string){}': {
raworiginal: 'function foo(numVal: number, strVal: string){}',
transformed: 'function foo(numVal , strVal ){}',
eval: 'No error',
},
'function foo(numVal: number, untypedVal){}': {
raworiginal: 'function foo(numVal: number, untypedVal){}',
transformed: 'function foo(numVal , untypedVal){}',
eval: 'No error',
},
'function foo(untypedVal, numVal: number){}': {
raworiginal: 'function foo(untypedVal, numVal: number){}',
transformed: 'function foo(untypedVal, numVal ){}',
eval: 'No error',
},
'function foo(nullableNum: ?number){}': {
raworiginal: 'function foo(nullableNum: ?number){}',
transformed: 'function foo(nullableNum ){}',
eval: 'No error',
},
'function foo(callback: () => void){}': {
raworiginal: 'function foo(callback: () => void){}',
transformed: 'function foo(callback ){}',
eval: 'No error',
},
'function foo(callback: () => number){}': {
raworiginal: 'function foo(callback: () => number){}',
transformed: 'function foo(callback ){}',
eval: 'No error',
},
'function foo(callback: (_:bool) => number){}': {
raworiginal: 'function foo(callback: (_:bool) => number){}',
transformed: 'function foo(callback ){}',
eval: 'No error',
},
'function foo(callback: (_1:bool, _2:string) => number){}': {
raworiginal: 'function foo(callback: (_1:bool, _2:string) => number){}',
transformed: 'function foo(callback ){}',
eval: 'No error',
},
'function foo(callback: (_1:bool, ...foo:Array<number>) => number){}': {
raworiginal: 'function foo(callback: (_1:bool, ...foo:Array<number>) => number){}',
transformed: 'function foo(callback ){}',
eval: 'No error',
},
'function foo():number{}': {
raworiginal: 'function foo():number{}',
transformed: 'function foo() {}',
eval: 'No error',
},
'function foo():() => void{}': {
raworiginal: 'function foo():() => void{}',
transformed: 'function foo() {}',
eval: 'No error',
},
'function foo():(_:bool) => number{}': {
raworiginal: 'function foo():(_:bool) => number{}',
transformed: 'function foo() {}',
eval: 'No error',
},
'function foo():(_?:bool) => number{}': {
raworiginal: 'function foo():(_?:bool) => number{}',
transformed: 'function foo() {}',
eval: 'No error',
},
'function foo(): {} {}': {
raworiginal: 'function foo(): {} {}',
transformed: 'function foo() {}',
eval: 'No error',
},
'function foo<T>() {}': {
raworiginal: 'function foo<T>() {}',
transformed: 'function foo () {}',
eval: 'No error',
},
'function foo<T: Foo>() {}': {
raworiginal: 'function foo<T: Foo>() {}',
transformed: 'function foo () {}',
eval: 'No error',
},
'function foo<T,S>() {}': {
raworiginal: 'function foo<T,S>() {}',
transformed: 'function foo () {}',
eval: 'No error',
},
'a=function<T,S>() {}': {
raworiginal: 'a=function<T,S>() {}',
transformed: 'a=function () {}',
eval: 'No error',
},
'a={set fooProp(value:number){}}': {
raworiginal: 'a={set fooProp(value:number){}}',
transformed: 'a={set fooProp(value ){}}',
eval: 'No error',
},
'a={set fooProp(value:number): void{}}': {
raworiginal: 'a={set fooProp(value:number): void{}}',
transformed: 'a={set fooProp(value ) {}}',
eval: 'No error',
},
'a={get fooProp(): number {}}': {
raworiginal: 'a={get fooProp(): number {}}',
transformed: 'a={get fooProp() {}}',
eval: 'No error',
},
'class Foo {set fooProp(value:number){}}': {
raworiginal: 'class Foo {set fooProp(value:number){}}',
transformed: 'class Foo {set fooProp(value ){}}',
eval: 'Unexpected reserved word',
},
'class Foo {set fooProp(value:number): void{}}': {
raworiginal: 'class Foo {set fooProp(value:number): void{}}',
transformed: 'class Foo {set fooProp(value ) {}}',
eval: 'Unexpected reserved word',
},
'class Foo {get fooProp(): number{}}': {
raworiginal: 'class Foo {get fooProp(): number{}}',
transformed: 'class Foo {get fooProp() {}}',
eval: 'Unexpected reserved word',
},
'var numVal:number;': {
raworiginal: 'var numVal:number;',
transformed: 'var numVal ;',
eval: 'No error',
},
'var numVal:number = otherNumVal;': {
raworiginal: 'var numVal:number = otherNumVal;',
transformed: 'var numVal = otherNumVal;',
eval: 'otherNumVal is not defined',
},
'var a: {numVal: number};': {
raworiginal: 'var a: {numVal: number};',
transformed: 'var a ;',
eval: 'No error',
},
'var a: {numVal: number;};': {
raworiginal: 'var a: {numVal: number;};',
transformed: 'var a ;',
eval: 'No error',
},
'var a: {numVal: number; [indexer: string]: number};': {
raworiginal: 'var a: {numVal: number; [indexer: string]: number};',
transformed: 'var a ;',
eval: 'No error',
},
'var a: ?{numVal: number};': {
raworiginal: 'var a: ?{numVal: number};',
transformed: 'var a ;',
eval: 'No error',
},
'var a: {numVal: number; strVal: string}': {
raworiginal: 'var a: {numVal: number; strVal: string}',
transformed: 'var a ',
eval: 'No error',
},
'var a: {subObj: {strVal: string}}': {
raworiginal: 'var a: {subObj: {strVal: string}}',
transformed: 'var a ',
eval: 'No error',
},
'var a: {subObj: ?{strVal: string}}': {
raworiginal: 'var a: {subObj: ?{strVal: string}}',
transformed: 'var a ',
eval: 'No error',
},
'var a: {param1: number; param2: string}': {
raworiginal: 'var a: {param1: number; param2: string}',
transformed: 'var a ',
eval: 'No error',
},
'var a: {param1: number; param2?: string}': {
raworiginal: 'var a: {param1: number; param2?: string}',
transformed: 'var a ',
eval: 'No error',
},
'var a: {add(x:number, ...y:Array<string>): void}': {
raworiginal: 'var a: {add(x:number, ...y:Array<string>): void}',
transformed: 'var a ',
eval: 'No error',
},
'var a: { id<T>(x: T): T; }': {
raworiginal: 'var a: { id<T>(x: T): T; }',
transformed: 'var a ',
eval: 'No error',
},
'var a:Array<number> = [1, 2, 3]': {
raworiginal: 'var a:Array<number> = [1, 2, 3]',
transformed: 'var a = [1, 2, 3]',
eval: 'No error',
},
'a = class Foo<T> { }': {
raworiginal: 'a = class Foo<T> { }',
transformed: 'a = class Foo<T> { }',
eval: 'Unexpected reserved word',
},
'a = class Foo<T> extends Bar<T> { }': {
raworiginal: 'a = class Foo<T> extends Bar<T> { }',
transformed: 'a = class Foo<T> extends Bar<T> { }',
eval: 'Unexpected reserved word',
},
'class Foo<T> {}': {
raworiginal: 'class Foo<T> {}',
transformed: 'class Foo<T> {}',
eval: 'Unexpected reserved word',
},
'class Foo<T: Bar> {}': {
raworiginal: 'class Foo<T: Bar> {}',
transformed: 'class Foo<T > {}',
eval: 'Unexpected reserved word',
},
'class Foo<T> extends Bar<T> { }': {
raworiginal: 'class Foo<T> extends Bar<T> { }',
transformed: 'class Foo<T> extends Bar<T> { }',
eval: 'Unexpected reserved word',
},
'class Foo<T> extends mixin(Bar) { }': {
raworiginal: 'class Foo<T> extends mixin(Bar) { }',
transformed: 'class Foo<T> extends mixin(Bar) { }',
eval: 'Unexpected reserved word',
},
'class Foo<T> { bar<U>():number { return 42; }}': {
raworiginal: 'class Foo<T> { bar<U>():number { return 42; }}',
transformed: 'class Foo<T> { bar<U>() { return 42; }}',
eval: 'Unexpected reserved word',
},
'class Foo { "bar"<T>() { } }': {
raworiginal: 'class Foo { "bar"<T>() { } }',
transformed: 'class Foo { "bar"<T>() { } }',
eval: 'Unexpected reserved word',
},
'function foo(requiredParam, optParam?) {}': {
raworiginal: 'function foo(requiredParam, optParam?) {}',
transformed: 'function foo(requiredParam, optParam ) {}',
eval: 'No error',
},
'class Foo { prop1:string; prop2:number; }': {
raworiginal: 'class Foo { prop1:string; prop2:number; }',
transformed: 'class Foo { }',
eval: 'Unexpected reserved word',
},
'var x : number | string = 4;': {
raworiginal: 'var x : number | string = 4;',
transformed: 'var x = 4;',
eval: 'No error',
},
'class Array { concat(items:number | string) {}; }': {
raworiginal: 'class Array { concat(items:number | string) {}; }',
transformed: 'class Array { concat(items ) {}; }',
eval: 'Unexpected reserved word',
},
'var x : () => number | () => string = fn;': {
raworiginal: 'var x : () => number | () => string = fn;',
transformed: 'var x = fn;',
eval: 'fn is not defined',
},
'var x: typeof Y = Y;': {
raworiginal: 'var x: typeof Y = Y;',
transformed: 'var x = Y;',
eval: 'Y is not defined',
},
'var x: typeof Y | number = Y;': {
raworiginal: 'var x: typeof Y | number = Y;',
transformed: 'var x = Y;',
eval: 'Y is not defined',
},
'var {x}: {x: string; } = { x: "hello" };': {
raworiginal: 'var {x}: {x: string; } = { x: "hello" };',
transformed: 'var {x} = { x: "hello" };',
eval: 'Unexpected token {',
},
'var {x}: {x: string } = { x: "hello" };': {
raworiginal: 'var {x}: {x: string } = { x: "hello" };',
transformed: 'var {x} = { x: "hello" };',
eval: 'Unexpected token {',
},
'var [x]: Array<string> = [ "hello" ];': {
raworiginal: 'var [x]: Array<string> = [ "hello" ];',
transformed: 'var [x] = [ "hello" ];',
eval: 'Unexpected token [',
},
'function foo({x}: { x: string; }) {}': {
raworiginal: 'function foo({x}: { x: string; }) {}',
transformed: 'function foo({x} ) {}',
eval: 'Unexpected token {',
},
'function foo([x]: Array<string>) {}': {
raworiginal: 'function foo([x]: Array<string>) {}',
transformed: 'function foo([x] ) {}',
eval: 'Unexpected token [',
},
'function foo(...rest: Array<number>) {}': {
raworiginal: 'function foo(...rest: Array<number>) {}',
transformed: 'function foo(...rest ) {}',
eval: 'Unexpected token .',
},
'(function (...rest: Array<number>) {})': {
raworiginal: '(function (...rest: Array<number>) {})',
transformed: '(function (...rest ) {})',
eval: 'Unexpected token .',
},
'((...rest: Array<number>) => rest)': {
raworiginal: '((...rest: Array<number>) => rest)',
transformed: '((...rest ) => rest)',
eval: 'Unexpected token .',
},
'var a: Map<string, Array<string> >': {
raworiginal: 'var a: Map<string, Array<string> >',
transformed: 'var a ',
eval: 'No error',
},
'var a: Map<string, Array<string>>': {
raworiginal: 'var a: Map<string, Array<string>>',
transformed: 'var a ',
eval: 'No error',
},
'var a: number[]': {
raworiginal: 'var a: number[]',
transformed: 'var a ',
eval: 'No error',
},
'var a: ?string[]': {
raworiginal: 'var a: ?string[]',
transformed: 'var a ',
eval: 'No error',
},
'var a: Promise<bool>[]': {
raworiginal: 'var a: Promise<bool>[]',
transformed: 'var a ',
eval: 'No error',
},
'var a:(...rest:Array<number>) => number': {
raworiginal: 'var a:(...rest:Array<number>) => number',
transformed: 'var a ',
eval: 'No error',
},
"TypeAnnotations": {
"function foo(numVal: any){}": {
"raworiginal": "function foo(numVal: any){}",
"transformed": "function foo(numVal ){}",
"eval": "No error"
},
'Type Alias': {
'type FBID = number;': {
raworiginal: 'type FBID = number;',
transformed: ' ',
eval: 'No error',
},
'type Foo<T> = Bar<T>': {
raworiginal: 'type Foo<T> = Bar<T>',
transformed: ' ',
eval: 'No error',
},
"function foo(numVal: number){}": {
"raworiginal": "function foo(numVal: number){}",
"transformed": "function foo(numVal ){}",
"eval": "No error"
},
'Interfaces': {
'interface A {}': {
raworiginal: 'interface A {}',
transformed: ' ',
eval: 'No error',
},
'interface A extends B {}': {
raworiginal: 'interface A extends B {}',
transformed: ' ',
eval: 'No error',
},
'interface A<T> extends B<T>, C<T> {}': {
raworiginal: 'interface A<T> extends B<T>, C<T> {}',
transformed: ' ',
eval: 'No error',
},
'interface A { foo: () => number; }': {
raworiginal: 'interface A { foo: () => number; }',
transformed: ' ',
eval: 'No error',
},
'interface Dictionary { [index: string]: string; length: number; }': {
raworiginal: 'interface Dictionary { [index: string]: string; length: number; }',
transformed: ' ',
eval: 'No error',
},
'class Foo implements Bar {}': {
raworiginal: 'class Foo implements Bar {}',
transformed: 'class Foo implements Bar {}',
eval: 'Unexpected reserved word',
},
'class Foo extends Bar implements Bat, Man<number> {}': {
raworiginal: 'class Foo extends Bar implements Bat, Man<number> {}',
transformed: 'class Foo extends Bar implements Bat, Man<number> {}',
eval: 'Unexpected reserved word',
},
'class Foo extends class Bar implements Bat {} {}': {
raworiginal: 'class Foo extends class Bar implements Bat {} {}',
transformed: 'class Foo extends class Bar implements Bat {} {}',
eval: 'Unexpected reserved word',
},
'class Foo extends class Bar implements Bat {} implements Man {}': {
raworiginal: 'class Foo extends class Bar implements Bat {} implements Man {}',
transformed: 'class Foo extends class Bar implements Bat {} implements Man {}',
eval: 'Unexpected reserved word',
},
"function foo(numVal: number, strVal: string){}": {
"raworiginal": "function foo(numVal: number, strVal: string){}",
"transformed": "function foo(numVal , strVal ){}",
"eval": "No error"
},
'Type Grouping': {
'var a: (number)': {
raworiginal: 'var a: (number)',
transformed: 'var a ',
eval: 'No error',
},
'var a: (() => number) | () => string': {
raworiginal: 'var a: (() => number) | () => string',
transformed: 'var a ',
eval: 'No error',
},
'var a: number & (string | bool)': {
raworiginal: 'var a: number & (string | bool)',
transformed: 'var a ',
eval: 'No error',
},
'var a: (typeof A)': {
raworiginal: 'var a: (typeof A)',
transformed: 'var a ',
eval: 'No error',
},
"function foo(numVal: number, untypedVal){}": {
"raworiginal": "function foo(numVal: number, untypedVal){}",
"transformed": "function foo(numVal , untypedVal){}",
"eval": "No error"
},
'XJS': {
'<a />': {
raworiginal: '<a />',
transformed: '<a />',
eval: 'Unexpected token <',
},
'<n:a n:v />': {
raworiginal: '<n:a n:v />',
transformed: '<n:a n:v />',
eval: 'Unexpected token <',
},
'<a n:foo="bar"> {value} <b><c /></b></a>': {
raworiginal: '<a n:foo="bar"> {value} <b><c /></b></a>',
transformed: '<a n:foo="bar"> {value} <b><c /></b></a>',
eval: 'Unexpected token <',
},
'<a b={" "} c=" " d="&amp;" e="id=1&group=2" f="&#123456789" g="&#123*;" h="&#x;" />': {
raworiginal: '<a b={" "} c=" " d="&amp;" e="id=1&group=2" f="&#123456789" g="&#123*;" h="&#x;" />',
transformed: '<a b={" "} c=" " d="&amp;" e="id=1&group=2" f="&#123456789" g="&#123*;" h="&#x;" />',
eval: 'Unexpected token <',
},
'<a\n/>': {
raworiginal: '<a\n/>',
transformed: '<a\n/>',
eval: 'Unexpected token <',
},
'<日本語></日本語>': {
raworiginal: '<日本語></日本語>',
transformed: '<日本語></日本語>',
eval: 'Unexpected token <',
},
'<AbC-def\n test="&#x0026;&#38;">\nbar\nbaz\r\n</AbC-def>': {
raworiginal: '<AbC-def\n test="&#x0026;&#38;">\nbar\nbaz\r\n</AbC-def>',
transformed: '<AbC-def\n test="&#x0026;&#38;">\nbar\nbaz\r\n</AbC-def>',
eval: 'Unexpected token <',
},
'<a b={x ? <c /> : <d />} />': {
raworiginal: '<a b={x ? <c /> : <d />} />',
transformed: '<a b={x ? <c /> : <d />} />',
eval: 'Unexpected token <',
},
'<a>{}</a>': {
raworiginal: '<a>{}</a>',
transformed: '<a>{}</a>',
eval: 'Unexpected token <',
},
'<a>{/* this is a comment */}</a>': {
raworiginal: '<a>{/* this is a comment */}</a>',
transformed: '<a>{/* this is a comment */}</a>',
eval: 'Unexpected token <',
},
'<div>@test content</div>': {
raworiginal: '<div>@test content</div>',
transformed: '<div>@test content</div>',
eval: 'Unexpected token <',
},
'<div><br />7x invalid-js-identifier</div>': {
raworiginal: '<div><br />7x invalid-js-identifier</div>',
transformed: '<div><br />7x invalid-js-identifier</div>',
eval: 'Unexpected token <',
},
'<LeftRight left=<a /> right=<b>monkeys</b> />': {
raworiginal: '<LeftRight left=<a /> right=<b>monkeys</b> />',
transformed: '<LeftRight left=<a /> right=<b>monkeys</b> />',
eval: 'Unexpected token <',
},
'<a.b></a.b>': {
raworiginal: '<a.b></a.b>',
transformed: '<a.b></a.b>',
eval: 'Unexpected token <',
},
'<a.b.c></a.b.c>': {
raworiginal: '<a.b.c></a.b.c>',
transformed: '<a.b.c></a.b.c>',
eval: 'Unexpected token <',
},
'(<div />) < x;': {
raworiginal: '(<div />) < x;',
transformed: '(<div />) < x;',
eval: 'Unexpected token <',
},
'<div {...props} />': {
raworiginal: '<div {...props} />',
transformed: '<div {...props} />',
eval: 'Unexpected token <',
},
'<div {...props} post="attribute" />': {
raworiginal: '<div {...props} post="attribute" />',
transformed: '<div {...props} post="attribute" />',
eval: 'Unexpected token <',
},
'<div pre="leading" pre2="attribute" {...props}></div>': {
raworiginal: '<div pre="leading" pre2="attribute" {...props}></div>',
transformed: '<div pre="leading" pre2="attribute" {...props}></div>',
eval: 'Unexpected token <',
},
'<a> </a>': {
raworiginal: '<a> </a>',
transformed: '<a> </a>',
eval: 'Unexpected token <',
},
"function foo(untypedVal, numVal: number){}": {
"raworiginal": "function foo(untypedVal, numVal: number){}",
"transformed": "function foo(untypedVal, numVal ){}",
"eval": "No error"
},
'Call Properties': {
'var a : { (): number }': {
raworiginal: 'var a : { (): number }',
transformed: 'var a ',
eval: 'No error',
},
'var a : { (): number; }': {
raworiginal: 'var a : { (): number; }',
transformed: 'var a ',
eval: 'No error',
},
'var a : { (): number; y: string; (x: string): string }': {
raworiginal: 'var a : { (): number; y: string; (x: string): string }',
transformed: 'var a ',
eval: 'No error',
},
'var a : { <T>(x: T): number; }': {
raworiginal: 'var a : { <T>(x: T): number; }',
transformed: 'var a ',
eval: 'No error',
},
'interface A { (): number; }': {
raworiginal: 'interface A { (): number; }',
transformed: ' ',
eval: 'No error',
},
"function foo(nullableNum: ?number){}": {
"raworiginal": "function foo(nullableNum: ?number){}",
"transformed": "function foo(nullableNum ){}",
"eval": "No error"
},
'String Literal Types': {
'function createElement(tagName: "div"): HTMLDivElement {}': {
raworiginal: 'function createElement(tagName: "div"): HTMLDivElement {}',
transformed: 'function createElement(tagName ) {}',
eval: 'No error',
},
'function createElement(tagName: \'div\'): HTMLDivElement {}': {
raworiginal: 'function createElement(tagName: \'div\'): HTMLDivElement {}',
transformed: 'function createElement(tagName ) {}',
eval: 'No error',
},
"function foo(callback: () => void){}": {
"raworiginal": "function foo(callback: () => void){}",
"transformed": "function foo(callback ){}",
"eval": "No error"
},
'Qualified Generic Type': {
'var a : A.B': {
raworiginal: 'var a : A.B',
transformed: 'var a ',
eval: 'No error',
},
'var a : A.B.C': {
raworiginal: 'var a : A.B.C',
transformed: 'var a ',
eval: 'No error',
},
'var a : A.B<T>': {
raworiginal: 'var a : A.B<T>',
transformed: 'var a ',
eval: 'No error',
},
'var a : typeof A.B<T>': {
raworiginal: 'var a : typeof A.B<T>',
transformed: 'var a ',
eval: 'No error',
},
"function foo(callback: () => number){}": {
"raworiginal": "function foo(callback: () => number){}",
"transformed": "function foo(callback ){}",
"eval": "No error"
},
'Declare Statements': {
'declare var foo': {
raworiginal: 'declare var foo',
transformed: ' ',
eval: 'No error',
},
'declare var foo;': {
raworiginal: 'declare var foo;',
transformed: ' ',
eval: 'No error',
},
'declare function foo(): void': {
raworiginal: 'declare function foo(): void',
transformed: ' ',
eval: 'No error',
},
'declare function foo(): void;': {
raworiginal: 'declare function foo(): void;',
transformed: ' ',
eval: 'No error',
},
'declare function foo<T>(): void;': {
raworiginal: 'declare function foo<T>(): void;',
transformed: ' ',
eval: 'No error',
},
'declare function foo(x: number, y: string): void;': {
raworiginal: 'declare function foo(x: number, y: string): void;',
transformed: ' ',
eval: 'No error',
},
'declare class A {}': {
raworiginal: 'declare class A {}',
transformed: ' ',
eval: 'No error',
},
'declare class A<T> extends B<T> { x: number }': {
raworiginal: 'declare class A<T> extends B<T> { x: number }',
transformed: ' ',
eval: 'No error',
},
'declare class A { static foo(): number; static x : string }': {
raworiginal: 'declare class A { static foo(): number; static x : string }',
transformed: ' ',
eval: 'No error',
},
'declare class A { static [ indexer: number]: string }': {
raworiginal: 'declare class A { static [ indexer: number]: string }',
transformed: ' ',
eval: 'No error',
},
'declare class A { static () : number }': {
raworiginal: 'declare class A { static () : number }',
transformed: ' ',
eval: 'No error',
},
"function foo(callback: (_:bool) => number){}": {
"raworiginal": "function foo(callback: (_:bool) => number){}",
"transformed": "function foo(callback ){}",
"eval": "No error"
},
'Declare Module': {
'declare module A {}': {
raworiginal: 'declare module A {}',
transformed: ' ',
eval: 'No error',
},
'declare module "./a/b.js" {}': {
raworiginal: 'declare module "./a/b.js" {}',
transformed: ' ',
eval: 'No error',
},
'declare module A { declare var x: number; }': {
raworiginal: 'declare module A { declare var x: number; }',
transformed: ' ',
eval: 'No error',
},
'declare module A { declare function foo(): number; }': {
raworiginal: 'declare module A { declare function foo(): number; }',
transformed: ' ',
eval: 'No error',
},
'declare module A { declare class B { foo(): number; } }': {
raworiginal: 'declare module A { declare class B { foo(): number; } }',
transformed: ' ',
eval: 'No error',
},
"function foo(callback: (_1:bool, _2:string) => number){}": {
"raworiginal": "function foo(callback: (_1:bool, _2:string) => number){}",
"transformed": "function foo(callback ){}",
"eval": "No error"
},
'Typecasts': {
'(xxx: number)': {
raworiginal: '(xxx: number)',
transformed: '(xxx )',
eval: 'xxx is not defined',
},
'({xxx: 0, yyy: "hey"}: {xxx: number; yyy: string})': {
raworiginal: '({xxx: 0, yyy: "hey"}: {xxx: number; yyy: string})',
transformed: '({xxx: 0, yyy: "hey"} )',
eval: 'No error',
},
'((xxx) => xxx + 1: (xxx: number) => number)': {
raworiginal: '((xxx) => xxx + 1: (xxx: number) => number)',
transformed: '((xxx) => xxx + 1 )',
eval: 'Unexpected token >',
},
'((xxx: number), (yyy: string))': {
raworiginal: '((xxx: number), (yyy: string))',
transformed: '((xxx ), (yyy ))',
eval: 'xxx is not defined',
},
'((xxx: any): number)': {
raworiginal: '((xxx: any): number)',
transformed: '((xxx ) )',
eval: 'xxx is not defined',
},
"function foo(callback: (_1:bool, ...foo:Array<number>) => number){}": {
"raworiginal": "function foo(callback: (_1:bool, ...foo:Array<number>) => number){}",
"transformed": "function foo(callback ){}",
"eval": "No error"
},
"function foo():number{}": {
"raworiginal": "function foo():number{}",
"transformed": "function foo() {}",
"eval": "No error"
},
"function foo():() => void{}": {
"raworiginal": "function foo():() => void{}",
"transformed": "function foo() {}",
"eval": "No error"
},
"function foo():(_:bool) => number{}": {
"raworiginal": "function foo():(_:bool) => number{}",
"transformed": "function foo() {}",
"eval": "No error"
},
"function foo():(_?:bool) => number{}": {
"raworiginal": "function foo():(_?:bool) => number{}",
"transformed": "function foo() {}",
"eval": "No error"
},
"function foo(): {} {}": {
"raworiginal": "function foo(): {} {}",
"transformed": "function foo() {}",
"eval": "No error"
},
"function foo<T>() {}": {
"raworiginal": "function foo<T>() {}",
"transformed": "function foo () {}",
"eval": "No error"
},
"function foo<T: Foo>() {}": {
"raworiginal": "function foo<T: Foo>() {}",
"transformed": "function foo () {}",
"eval": "No error"
},
"function foo<T,S>() {}": {
"raworiginal": "function foo<T,S>() {}",
"transformed": "function foo () {}",
"eval": "No error"
},
"a=function<T,S>() {}": {
"raworiginal": "a=function<T,S>() {}",
"transformed": "a=function () {}",
"eval": "No error"
},
"a={set fooProp(value:number){}}": {
"raworiginal": "a={set fooProp(value:number){}}",
"transformed": "a={set fooProp(value ){}}",
"eval": "No error"
},
"a={set fooProp(value:number): void{}}": {
"raworiginal": "a={set fooProp(value:number): void{}}",
"transformed": "a={set fooProp(value ) {}}",
"eval": "No error"
},
"a={get fooProp(): number {}}": {
"raworiginal": "a={get fooProp(): number {}}",
"transformed": "a={get fooProp() {}}",
"eval": "No error"
},
"class Foo {set fooProp(value:number){}}": {
"raworiginal": "class Foo {set fooProp(value:number){}}",
"transformed": "class Foo {set fooProp(value ){}}",
"eval": "Unexpected reserved word"
},
"class Foo {set fooProp(value:number): void{}}": {
"raworiginal": "class Foo {set fooProp(value:number): void{}}",
"transformed": "class Foo {set fooProp(value ) {}}",
"eval": "Unexpected reserved word"
},
"class Foo {get fooProp(): number{}}": {
"raworiginal": "class Foo {get fooProp(): number{}}",
"transformed": "class Foo {get fooProp() {}}",
"eval": "Unexpected reserved word"
},
"var numVal:number;": {
"raworiginal": "var numVal:number;",
"transformed": "var numVal ;",
"eval": "No error"
},
"var numVal:number = otherNumVal;": {
"raworiginal": "var numVal:number = otherNumVal;",
"transformed": "var numVal = otherNumVal;",
"eval": "otherNumVal is not defined"
},
"var a: {numVal: number};": {
"raworiginal": "var a: {numVal: number};",
"transformed": "var a ;",
"eval": "No error"
},
"var a: {numVal: number;};": {
"raworiginal": "var a: {numVal: number;};",
"transformed": "var a ;",
"eval": "No error"
},
"var a: {numVal: number; [indexer: string]: number};": {
"raworiginal": "var a: {numVal: number; [indexer: string]: number};",
"transformed": "var a ;",
"eval": "No error"
},
"var a: ?{numVal: number};": {
"raworiginal": "var a: ?{numVal: number};",
"transformed": "var a ;",
"eval": "No error"
},
"var a: {numVal: number; strVal: string}": {
"raworiginal": "var a: {numVal: number; strVal: string}",
"transformed": "var a ",
"eval": "No error"
},
"var a: {subObj: {strVal: string}}": {
"raworiginal": "var a: {subObj: {strVal: string}}",
"transformed": "var a ",
"eval": "No error"
},
"var a: {subObj: ?{strVal: string}}": {
"raworiginal": "var a: {subObj: ?{strVal: string}}",
"transformed": "var a ",
"eval": "No error"
},
"var a: {param1: number; param2: string}": {
"raworiginal": "var a: {param1: number; param2: string}",
"transformed": "var a ",
"eval": "No error"
},
"var a: {param1: number; param2?: string}": {
"raworiginal": "var a: {param1: number; param2?: string}",
"transformed": "var a ",
"eval": "No error"
},
"var a: {add(x:number, ...y:Array<string>): void}": {
"raworiginal": "var a: {add(x:number, ...y:Array<string>): void}",
"transformed": "var a ",
"eval": "No error"
},
"var a: { id<T>(x: T): T; }": {
"raworiginal": "var a: { id<T>(x: T): T; }",
"transformed": "var a ",
"eval": "No error"
},
"var a:Array<number> = [1, 2, 3]": {
"raworiginal": "var a:Array<number> = [1, 2, 3]",
"transformed": "var a = [1, 2, 3]",
"eval": "No error"
},
"a = class Foo<T> { }": {
"raworiginal": "a = class Foo<T> { }",
"transformed": "a = class Foo<T> { }",
"eval": "Unexpected reserved word"
},
"a = class Foo<T> extends Bar<T> { }": {
"raworiginal": "a = class Foo<T> extends Bar<T> { }",
"transformed": "a = class Foo<T> extends Bar<T> { }",
"eval": "Unexpected reserved word"
},
"class Foo<T> {}": {
"raworiginal": "class Foo<T> {}",
"transformed": "class Foo<T> {}",
"eval": "Unexpected reserved word"
},
"class Foo<T: Bar> {}": {
"raworiginal": "class Foo<T: Bar> {}",
"transformed": "class Foo<T > {}",
"eval": "Unexpected reserved word"
},
"class Foo<T> extends Bar<T> { }": {
"raworiginal": "class Foo<T> extends Bar<T> { }",
"transformed": "class Foo<T> extends Bar<T> { }",
"eval": "Unexpected reserved word"
},
"class Foo<T> extends mixin(Bar) { }": {
"raworiginal": "class Foo<T> extends mixin(Bar) { }",
"transformed": "class Foo<T> extends mixin(Bar) { }",
"eval": "Unexpected reserved word"
},
"class Foo<T> { bar<U>():number { return 42; }}": {
"raworiginal": "class Foo<T> { bar<U>():number { return 42; }}",
"transformed": "class Foo<T> { bar<U>() { return 42; }}",
"eval": "Unexpected reserved word"
},
"class Foo { \"bar\"<T>() { } }": {
"raworiginal": "class Foo { \"bar\"<T>() { } }",
"transformed": "class Foo { \"bar\"<T>() { } }",
"eval": "Unexpected reserved word"
},
"function foo(requiredParam, optParam?) {}": {
"raworiginal": "function foo(requiredParam, optParam?) {}",
"transformed": "function foo(requiredParam, optParam ) {}",
"eval": "No error"
},
"class Foo { prop1:string; prop2:number; }": {
"raworiginal": "class Foo { prop1:string; prop2:number; }",
"transformed": "class Foo { }",
"eval": "Unexpected reserved word"
},
"var x : number | string = 4;": {
"raworiginal": "var x : number | string = 4;",
"transformed": "var x = 4;",
"eval": "No error"
},
"class Array { concat(items:number | string) {}; }": {
"raworiginal": "class Array { concat(items:number | string) {}; }",
"transformed": "class Array { concat(items ) {}; }",
"eval": "Unexpected reserved word"
},
"var x : () => number | () => string = fn;": {
"raworiginal": "var x : () => number | () => string = fn;",
"transformed": "var x = fn;",
"eval": "fn is not defined"
},
"var x: typeof Y = Y;": {
"raworiginal": "var x: typeof Y = Y;",
"transformed": "var x = Y;",
"eval": "Y is not defined"
},
"var x: typeof Y | number = Y;": {
"raworiginal": "var x: typeof Y | number = Y;",
"transformed": "var x = Y;",
"eval": "Y is not defined"
},
"var {x}: {x: string; } = { x: \"hello\" };": {
"raworiginal": "var {x}: {x: string; } = { x: \"hello\" };",
"transformed": "var {x} = { x: \"hello\" };",
"eval": "Unexpected token {"
},
"var {x}: {x: string } = { x: \"hello\" };": {
"raworiginal": "var {x}: {x: string } = { x: \"hello\" };",
"transformed": "var {x} = { x: \"hello\" };",
"eval": "Unexpected token {"
},
"var [x]: Array<string> = [ \"hello\" ];": {
"raworiginal": "var [x]: Array<string> = [ \"hello\" ];",
"transformed": "var [x] = [ \"hello\" ];",
"eval": "Unexpected token ["
},
"function foo({x}: { x: string; }) {}": {
"raworiginal": "function foo({x}: { x: string; }) {}",
"transformed": "function foo({x} ) {}",
"eval": "Unexpected token {"
},
"function foo([x]: Array<string>) {}": {
"raworiginal": "function foo([x]: Array<string>) {}",
"transformed": "function foo([x] ) {}",
"eval": "Unexpected token ["
},
"function foo(...rest: Array<number>) {}": {
"raworiginal": "function foo(...rest: Array<number>) {}",
"transformed": "function foo(...rest ) {}",
"eval": "Unexpected token ."
},
"(function (...rest: Array<number>) {})": {
"raworiginal": "(function (...rest: Array<number>) {})",
"transformed": "(function (...rest ) {})",
"eval": "Unexpected token ."
},
"((...rest: Array<number>) => rest)": {
"raworiginal": "((...rest: Array<number>) => rest)",
"transformed": "((...rest ) => rest)",
"eval": "Unexpected token ."
},
"var a: Map<string, Array<string> >": {
"raworiginal": "var a: Map<string, Array<string> >",
"transformed": "var a ",
"eval": "No error"
},
"var a: Map<string, Array<string>>": {
"raworiginal": "var a: Map<string, Array<string>>",
"transformed": "var a ",
"eval": "No error"
},
"var a: number[]": {
"raworiginal": "var a: number[]",
"transformed": "var a ",
"eval": "No error"
},
"var a: ?string[]": {
"raworiginal": "var a: ?string[]",
"transformed": "var a ",
"eval": "No error"
},
"var a: Promise<bool>[]": {
"raworiginal": "var a: Promise<bool>[]",
"transformed": "var a ",
"eval": "No error"
},
"var a:(...rest:Array<number>) => number": {
"raworiginal": "var a:(...rest:Array<number>) => number",
"transformed": "var a ",
"eval": "No error"
}
},
"Type Alias": {
"type FBID = number;": {
"raworiginal": "type FBID = number;",
"transformed": " ",
"eval": "No error"
},
"type Foo<T> = Bar<T>": {
"raworiginal": "type Foo<T> = Bar<T>",
"transformed": " ",
"eval": "No error"
}
},
"Interfaces": {
"interface A {}": {
"raworiginal": "interface A {}",
"transformed": " ",
"eval": "No error"
},
"interface A extends B {}": {
"raworiginal": "interface A extends B {}",
"transformed": " ",
"eval": "No error"
},
"interface A<T> extends B<T>, C<T> {}": {
"raworiginal": "interface A<T> extends B<T>, C<T> {}",
"transformed": " ",
"eval": "No error"
},
"interface A { foo: () => number; }": {
"raworiginal": "interface A { foo: () => number; }",
"transformed": " ",
"eval": "No error"
},
"interface Dictionary { [index: string]: string; length: number; }": {
"raworiginal": "interface Dictionary { [index: string]: string; length: number; }",
"transformed": " ",
"eval": "No error"
},
"class Foo implements Bar {}": {
"raworiginal": "class Foo implements Bar {}",
"transformed": "class Foo implements Bar {}",
"eval": "Unexpected reserved word"
},
"class Foo extends Bar implements Bat, Man<number> {}": {
"raworiginal": "class Foo extends Bar implements Bat, Man<number> {}",
"transformed": "class Foo extends Bar implements Bat, Man<number> {}",
"eval": "Unexpected reserved word"
},
"class Foo extends class Bar implements Bat {} {}": {
"raworiginal": "class Foo extends class Bar implements Bat {} {}",
"transformed": "class Foo extends class Bar implements Bat {} {}",
"eval": "Unexpected reserved word"
},
"class Foo extends class Bar implements Bat {} implements Man {}": {
"raworiginal": "class Foo extends class Bar implements Bat {} implements Man {}",
"transformed": "class Foo extends class Bar implements Bat {} implements Man {}",
"eval": "Unexpected reserved word"
}
},
"Type Grouping": {
"var a: (number)": {
"raworiginal": "var a: (number)",
"transformed": "var a ",
"eval": "No error"
},
"var a: (() => number) | () => string": {
"raworiginal": "var a: (() => number) | () => string",
"transformed": "var a ",
"eval": "No error"
},
"var a: number & (string | bool)": {
"raworiginal": "var a: number & (string | bool)",
"transformed": "var a ",
"eval": "No error"
},
"var a: (typeof A)": {
"raworiginal": "var a: (typeof A)",
"transformed": "var a ",
"eval": "No error"
}
},
"XJS": {
"<a />": {
"raworiginal": "<a />",
"transformed": "<a />",
"eval": "Unexpected token <"
},
"<n:a n:v />": {
"raworiginal": "<n:a n:v />",
"transformed": "<n:a n:v />",
"eval": "Unexpected token <"
},
"<a n:foo=\"bar\"> {value} <b><c /></b></a>": {
"raworiginal": "<a n:foo=\"bar\"> {value} <b><c /></b></a>",
"transformed": "<a n:foo=\"bar\"> {value} <b><c /></b></a>",
"eval": "Unexpected token <"
},
"<a b={\" \"} c=\" \" d=\"&amp;\" e=\"id=1&group=2\" f=\"&#123456789\" g=\"&#123*;\" h=\"&#x;\" />": {
"raworiginal": "<a b={\" \"} c=\" \" d=\"&amp;\" e=\"id=1&group=2\" f=\"&#123456789\" g=\"&#123*;\" h=\"&#x;\" />",
"transformed": "<a b={\" \"} c=\" \" d=\"&amp;\" e=\"id=1&group=2\" f=\"&#123456789\" g=\"&#123*;\" h=\"&#x;\" />",
"eval": "Unexpected token <"
},
"<a\n/>": {
"raworiginal": "<a\n/>",
"transformed": "<a\n/>",
"eval": "Unexpected token <"
},
"<日本語></日本語>": {
"raworiginal": "<日本語></日本語>",
"transformed": "<日本語></日本語>",
"eval": "Unexpected token <"
},
"<AbC-def\n test=\"&#x0026;&#38;\">\nbar\nbaz\r\n</AbC-def>": {
"raworiginal": "<AbC-def\n test=\"&#x0026;&#38;\">\nbar\nbaz\r\n</AbC-def>",
"transformed": "<AbC-def\n test=\"&#x0026;&#38;\">\nbar\nbaz\r\n</AbC-def>",
"eval": "Unexpected token <"
},
"<a b={x ? <c /> : <d />} />": {
"raworiginal": "<a b={x ? <c /> : <d />} />",
"transformed": "<a b={x ? <c /> : <d />} />",
"eval": "Unexpected token <"
},
"<a>{}</a>": {
"raworiginal": "<a>{}</a>",
"transformed": "<a>{}</a>",
"eval": "Unexpected token <"
},
"<a>{/* this is a comment */}</a>": {
"raworiginal": "<a>{/* this is a comment */}</a>",
"transformed": "<a>{/* this is a comment */}</a>",
"eval": "Unexpected token <"
},
"<div>@test content</div>": {
"raworiginal": "<div>@test content</div>",
"transformed": "<div>@test content</div>",
"eval": "Unexpected token <"
},
"<div><br />7x invalid-js-identifier</div>": {
"raworiginal": "<div><br />7x invalid-js-identifier</div>",
"transformed": "<div><br />7x invalid-js-identifier</div>",
"eval": "Unexpected token <"
},
"<LeftRight left=<a /> right=<b>monkeys</b> />": {
"raworiginal": "<LeftRight left=<a /> right=<b>monkeys</b> />",
"transformed": "<LeftRight left=<a /> right=<b>monkeys</b> />",
"eval": "Unexpected token <"
},
"<a.b></a.b>": {
"raworiginal": "<a.b></a.b>",
"transformed": "<a.b></a.b>",
"eval": "Unexpected token <"
},
"<a.b.c></a.b.c>": {
"raworiginal": "<a.b.c></a.b.c>",
"transformed": "<a.b.c></a.b.c>",
"eval": "Unexpected token <"
},
"(<div />) < x;": {
"raworiginal": "(<div />) < x;",
"transformed": "(<div />) < x;",
"eval": "Unexpected token <"
},
"<div {...props} />": {
"raworiginal": "<div {...props} />",
"transformed": "<div {...props} />",
"eval": "Unexpected token <"
},
"<div {...props} post=\"attribute\" />": {
"raworiginal": "<div {...props} post=\"attribute\" />",
"transformed": "<div {...props} post=\"attribute\" />",
"eval": "Unexpected token <"
},
"<div pre=\"leading\" pre2=\"attribute\" {...props}></div>": {
"raworiginal": "<div pre=\"leading\" pre2=\"attribute\" {...props}></div>",
"transformed": "<div pre=\"leading\" pre2=\"attribute\" {...props}></div>",
"eval": "Unexpected token <"
},
"<a> </a>": {
"raworiginal": "<a> </a>",
"transformed": "<a> </a>",
"eval": "Unexpected token <"
}
},
"Call Properties": {
"var a : { (): number }": {
"raworiginal": "var a : { (): number }",
"transformed": "var a ",
"eval": "No error"
},
"var a : { (): number; }": {
"raworiginal": "var a : { (): number; }",
"transformed": "var a ",
"eval": "No error"
},
"var a : { (): number; y: string; (x: string): string }": {
"raworiginal": "var a : { (): number; y: string; (x: string): string }",
"transformed": "var a ",
"eval": "No error"
},
"var a : { <T>(x: T): number; }": {
"raworiginal": "var a : { <T>(x: T): number; }",
"transformed": "var a ",
"eval": "No error"
},
"interface A { (): number; }": {
"raworiginal": "interface A { (): number; }",
"transformed": " ",
"eval": "No error"
}
},
"String Literal Types": {
"function createElement(tagName: \"div\"): HTMLDivElement {}": {
"raworiginal": "function createElement(tagName: \"div\"): HTMLDivElement {}",
"transformed": "function createElement(tagName ) {}",
"eval": "No error"
},
"function createElement(tagName: 'div'): HTMLDivElement {}": {
"raworiginal": "function createElement(tagName: 'div'): HTMLDivElement {}",
"transformed": "function createElement(tagName ) {}",
"eval": "No error"
}
},
"Qualified Generic Type": {
"var a : A.B": {
"raworiginal": "var a : A.B",
"transformed": "var a ",
"eval": "No error"
},
"var a : A.B.C": {
"raworiginal": "var a : A.B.C",
"transformed": "var a ",
"eval": "No error"
},
"var a : A.B<T>": {
"raworiginal": "var a : A.B<T>",
"transformed": "var a ",
"eval": "No error"
},
"var a : typeof A.B<T>": {
"raworiginal": "var a : typeof A.B<T>",
"transformed": "var a ",
"eval": "No error"
}
},
"Declare Statements": {
"declare var foo": {
"raworiginal": "declare var foo",
"transformed": " ",
"eval": "No error"
},
"declare var foo;": {
"raworiginal": "declare var foo;",
"transformed": " ",
"eval": "No error"
},
"declare function foo(): void": {
"raworiginal": "declare function foo(): void",
"transformed": " ",
"eval": "No error"
},
"declare function foo(): void;": {
"raworiginal": "declare function foo(): void;",
"transformed": " ",
"eval": "No error"
},
"declare function foo<T>(): void;": {
"raworiginal": "declare function foo<T>(): void;",
"transformed": " ",
"eval": "No error"
},
"declare function foo(x: number, y: string): void;": {
"raworiginal": "declare function foo(x: number, y: string): void;",
"transformed": " ",
"eval": "No error"
},
"declare class A {}": {
"raworiginal": "declare class A {}",
"transformed": " ",
"eval": "No error"
},
"declare class A<T> extends B<T> { x: number }": {
"raworiginal": "declare class A<T> extends B<T> { x: number }",
"transformed": " ",
"eval": "No error"
},
"declare class A { static foo(): number; static x : string }": {
"raworiginal": "declare class A { static foo(): number; static x : string }",
"transformed": " ",
"eval": "No error"
},
"declare class A { static [ indexer: number]: string }": {
"raworiginal": "declare class A { static [ indexer: number]: string }",
"transformed": " ",
"eval": "No error"
},
"declare class A { static () : number }": {
"raworiginal": "declare class A { static () : number }",
"transformed": " ",
"eval": "No error"
}
},
"Declare Module": {
"declare module A {}": {
"raworiginal": "declare module A {}",
"transformed": " ",
"eval": "No error"
},
"declare module \"./a/b.js\" {}": {
"raworiginal": "declare module \"./a/b.js\" {}",
"transformed": " ",
"eval": "No error"
},
"declare module A { declare var x: number; }": {
"raworiginal": "declare module A { declare var x: number; }",
"transformed": " ",
"eval": "No error"
},
"declare module A { declare function foo(): number; }": {
"raworiginal": "declare module A { declare function foo(): number; }",
"transformed": " ",
"eval": "No error"
},
"declare module A { declare class B { foo(): number; } }": {
"raworiginal": "declare module A { declare class B { foo(): number; } }",
"transformed": " ",
"eval": "No error"
}
},
"Typecasts": {
"(xxx: number)": {
"raworiginal": "(xxx: number)",
"transformed": "(xxx )",
"eval": "xxx is not defined"
},
"({xxx: 0, yyy: \"hey\"}: {xxx: number; yyy: string})": {
"raworiginal": "({xxx: 0, yyy: \"hey\"}: {xxx: number; yyy: string})",
"transformed": "({xxx: 0, yyy: \"hey\"} )",
"eval": "No error"
},
"((xxx) => xxx + 1: (xxx: number) => number)": {
"raworiginal": "((xxx) => xxx + 1: (xxx: number) => number)",
"transformed": "((xxx) => xxx + 1 )",
"eval": "Unexpected token >"
},
"((xxx: number), (yyy: string))": {
"raworiginal": "((xxx: number), (yyy: string))",
"transformed": "((xxx ), (yyy ))",
"eval": "xxx is not defined"
},
"((xxx: any): number)": {
"raworiginal": "((xxx: any): number)",
"transformed": "((xxx ) )",
"eval": "xxx is not defined"
}
}
};
/**
* Copyright 2014 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 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.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @emails jeffmo@fb.com

@@ -43,5 +36,10 @@ */

expect(transform(code)).toEqual('foo["delete"];');
});
code = '(foo++).delete;';
it('should handle parenthesis', function() {
var code = '(foo++).delete;';
expect(transform(code)).toEqual('(foo++)["delete"];');
code = '(foo.bar()).delete;';
expect(transform(code)).toEqual('(foo.bar())["delete"];');
});

@@ -60,2 +58,17 @@

});
it('should work with newlines', function() {
var code = 'foo.\ncatch();';
expect(transform(code)).toEqual('foo\n["catch"]();');
// This one is weird but it works.
code = 'foo.\n catch();';
expect(transform(code)).toEqual('foo\n ["catch"]();');
code = 'foo\n.catch();';
expect(transform(code)).toEqual('foo\n["catch"]();');
code = 'foo\n .catch();';
expect(transform(code)).toEqual('foo\n ["catch"]();');
});
});

@@ -62,0 +75,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -33,13 +26,11 @@

function transform(code, visitors) {
var opts = {sourceType: 'nonStrictModule'};
code = jstransform.transform(
flowSyntaxVisitors,
code.join('\n'),
{sourceType: 'nonStrictModule'}
opts
).code;
if (visitors) {
code = jstransform.transform(
visitors,
code
).code;
code = jstransform.transform(visitors, code, opts).code;
}

@@ -64,3 +55,3 @@

it('strips import-type declarations', () => {
it('strips import-type statements', () => {
var code = transform([

@@ -74,2 +65,11 @@ 'import type DefaultExport from "MyModule";',

it('strips export-type statements', () => {
var code = transform([
'export type foo = number;',
'var sanityCheck = 42;',
]);
eval(code);
expect(sanityCheck).toBe(42);
});
it('catches up correctly', () => {

@@ -76,0 +76,0 @@ var code = transform([

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

@@ -0,1 +1,10 @@

/**
* Copyright 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.
*/
/*jshint evil: true*/

@@ -169,27 +178,31 @@ /*jshint loopfunc: true*/

require('mock-modules').autoMockOff();
var tests = require("./gen/type-syntax-test.rec.js");
var jstransform = require('../../src/jstransform');
var tests = require('./gen/type-syntax-test.rec.js');
var transform = require('../../src/jstransform').transform;
var visitors = require('../type-syntax').visitorList;
describe('transforms match expectations', function () {
for (var section in tests) {
for (var test in tests[section]) {
it('transforms "'+test+'"', function (section, test) { return function () {
var transformed = jstransform.transform(visitors, test).code;
expect(transformed).toBe(tests[section][test].transformed);
}; } (section, test));
it('evals "'+test+'"', function (section, test) { return function () {
var evalResult;
var transformed = jstransform.transform(visitors, test).code;
try {
describe('transforms match expectations', function() {
Object.keys(tests).forEach(function(sectionName) {
var section = tests[sectionName];
Object.keys(section).forEach(function(testCode) {
it('transforms "' + testCode + '"', function() {
expect(transform(visitors, testCode).code).toBe(section[testCode].transformed);
});
it('evals "' + testCode + '"', function() {
var transformed = transform(visitors, testCode).code;
var expected = section[testCode].eval;
var evalFn = function() {
eval(transformed);
evalResult = "No error";
} catch (e) {
evalResult = e.message;
};
if (expected === 'No error') {
expect(evalFn).not.toThrow();
} else {
expect(evalFn).toThrow(expected);
}
expect(evalResult).toBe(tests[section][test].eval);
}; } (section, test));
}
}
});
});
});
});
}
/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -79,3 +72,5 @@

|| (node.type === Syntax.Identifier
&& node.name === "super");
&& node.name === "super")
|| (node.type === Syntax.JSXIdentifier
&& node.name === 'this');
});

@@ -82,0 +77,0 @@

/**
* Copyright 2004-present Facebook. All Rights Reserved.
* Copyright 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.
*/

@@ -50,3 +55,3 @@ /*global exports:true*/

// Input = max(1, 2, ...list)
// Output = max.apply(null, [1, 2].concat(list))
// Output = max.apply(undefined, [1, 2].concat(list))
var needsToBeWrappedInParenthesis =

@@ -62,3 +67,3 @@ node.callee.type === Syntax.FunctionDeclaration ||

}
utils.append('.apply(null', state);
utils.append('.apply(undefined', state);
}

@@ -65,0 +70,0 @@ utils.append(', ', state);

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -184,3 +177,3 @@

} else {
var methodAccessorComputed = false;
var methodAccessorComputed = methodNode.computed;
var methodAccessor;

@@ -187,0 +180,0 @@ var prototypeOrStatic = methodNode.static ? '' : '.prototype';

/**
* Copyright 2014 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/
/*global exports:true*/

@@ -17,0 +11,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -41,5 +34,3 @@

}
if (node.computed) { // [<expr>]() { ...}
utils.catchup(node.key.range[1] + 1, state);
} else if (reservedWordsHelper.isReservedWord(node.key.name)) {
if (reservedWordsHelper.isReservedWord(node.key.name)) {
utils.catchup(node.key.range[0], state);

@@ -52,12 +43,21 @@ utils.append('"', state);

utils.catchup(node.key.range[1], state);
utils.append(
':function' + (isGenerator ? '*' : ''),
state
);
path.unshift(node);
traverse(node.value, path, state);
path.shift();
utils.append(':', state);
renderConciseMethod(traverse, node, path, state);
return false;
}
// This method is also used by es6-object-computed-property-visitor to render
// the method for concise computed properties.
function renderConciseMethod(traverse, property, path, state) {
if (property.computed) {
var closingSquareBracketIndex = state.g.source.indexOf(']', property.key.range[1]);
utils.catchup(closingSquareBracketIndex, state);
utils.move(closingSquareBracketIndex + 1, state);
}
utils.append("function" + (property.value.generator ? "*" : ""), state);
path.unshift(property);
traverse(property.value, path, state);
path.shift();
}
visitObjectConciseMethod.test = function(node, path, state) {

@@ -69,4 +69,5 @@ return node.type === Syntax.Property &&

exports.renderConciseMethod = renderConciseMethod;
exports.visitorList = [
visitObjectConciseMethod
];
/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -66,2 +59,3 @@

utils.catchupWhiteSpace(node.rest.range[1], state);
utils.catchup(node.body.range[0], state);

@@ -68,0 +62,0 @@ path.unshift(node);

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -49,2 +42,5 @@

// those cases.
if (ii === 0) {
utils.append('"" + ', state);
}
if (ii > 0 && !templateElement.tail) {

@@ -60,2 +56,3 @@ // + between substitution and substitution

if (substitution.type === Syntax.Identifier ||
substitution.type === Syntax.Literal ||
substitution.type === Syntax.MemberExpression ||

@@ -62,0 +59,0 @@ substitution.type === Syntax.CallExpression) {

/**
* Copyright 2013 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2004-present Facebook. All Rights Reserved.
* Copyright 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.
*/

@@ -27,6 +32,32 @@ /*global exports:true*/

var previousWasSpread = false;
var lastWasSpread = renderSpreadProperties(
traverse,
node.properties,
path,
state,
false // previousWasSpread
);
for (var i = 0; i < node.properties.length; i++) {
var property = node.properties[i];
// Strip any non-whitespace between the last item and the end.
// We only catch up on whitespace so that we ignore any trailing commas which
// are stripped out for IE8 support. Unfortunately, this also strips out any
// trailing comments.
utils.catchupWhiteSpace(node.range[1] - 1, state);
// Skip the trailing }
utils.move(node.range[1], state);
if (!lastWasSpread) {
utils.append('}', state);
}
utils.append(')', state);
return false;
}
// This method is also used by es6-object-computed-property-visitor.
function renderSpreadProperties(traverse, properties, path, state, previousWasSpread) {
for (var i = 0; i < properties.length; i++) {
var property = properties[i];
if (property.type === Syntax.SpreadProperty) {

@@ -73,17 +104,3 @@

// Strip any non-whitespace between the last item and the end.
// We only catch up on whitespace so that we ignore any trailing commas which
// are stripped out for IE8 support. Unfortunately, this also strips out any
// trailing comments.
utils.catchupWhiteSpace(node.range[1] - 1, state);
// Skip the trailing }
utils.move(node.range[1], state);
if (!previousWasSpread) {
utils.append('}', state);
}
utils.append(')', state);
return false;
return previousWasSpread;
}

@@ -108,4 +125,5 @@

exports.renderSpreadProperties = renderSpreadProperties;
exports.visitorList = [
visitObjectLiteralSpread
];
/**
* Copyright 2014 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* 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.
*/

@@ -16,0 +9,0 @@

/**
* Copyright 2014 Facebook, Inc.
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 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.
*/

@@ -50,3 +42,10 @@ /*global exports:true*/

traverse(node.object, path, state);
utils.catchup(node.property.range[0] - 1, state);
// Member expression range does not include parenthesis, so simply specifying
// node.object.range[1] as the start position doesn't work. Neither does
// node.property.range[0] - 1 as that won't catch expressions that span
// newlines (period on previous line). So instead we'll catchup and remove
// any periods.
utils.catchup(node.property.range[0], state, function(s) {
return s.replace('.', '');
});
utils.append('[', state);

@@ -53,0 +52,0 @@ utils.catchupWhiteSpace(node.property.range[0], state);

@@ -0,1 +1,10 @@

/**
* Copyright 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.
*/
var esprima = require('esprima-fb');

@@ -156,8 +165,17 @@ var utils = require('../src/utils');

return node.type === 'ImportDeclaration'
&& node.isType;
&& (node.importKind === 'type' || node.importKind === 'typeof');
};
function visitExportType(traverse, node, path, state) {
utils.catchupWhiteOut(node.range[1], state);
}
visitExportType.test = function(node, path, state) {
return node.type === 'ExportDeclaration'
&& node.declaration.type === 'TypeAlias';
};
exports.visitorList = [
visitClassProperty,
visitDeclare,
visitExportType,
visitImportType,

@@ -164,0 +182,0 @@ visitInterfaceDeclaration,

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc