Added support for record and tuple syntax. (#10865)

* Added support for record and tuple syntax.

This commit adds support for both the hash #{} and bar {||}
syntaxes to babel-parser, as well as adds the supporting
babel-plugin-syntax-record-and-tuple plugin to enable support
for the syntax. Does not include any transform for records and
tuples.

* typo

* added check to ensure recordAndTuple in babel-parser

* switched to syntaxType option instead of explicit entries for each record and tuple type

* switched to using recordAndTupleSyntaxType for generator options instead of adding to node

* added tests for generator option recordAndTupleSyntaxType

* added test for record and tuple bar syntax with flow typings

* added tests for invalid/missing recordAndTuple syntaxType parser option

* fixed flowcheck errors

* fix merge with class privates in tokenizer

* Update packages/babel-parser/src/types.js

Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* improved recordAndTuple generator error message, added tests for invalid,missing options

* updated error messages for invalid parser syntaxType option

* updated error message

* added better error messages for when the recordAndTuple syntaxType is doesn't match the syntax used

* updated record and tuple support to use new error message templates

* added recordAndTuple to missing plugin helpers

* Fix linting

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
Rick Button
2020-03-16 18:57:44 -04:00
committed by GitHub
parent e06bf8ffdb
commit 3ce7c2e394
69 changed files with 2253 additions and 30 deletions

View File

@@ -0,0 +1,3 @@
src
test
*.log

View File

@@ -0,0 +1,19 @@
# @babel/plugin-syntax-record-and-tuple
> Allow parsing of records and tuples.
See our website [@babel/plugin-syntax-record-and-tuple](https://babeljs.io/docs/en/next/babel-plugin-syntax-record-and-tuple.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/plugin-syntax-record-and-tuple
```
or using yarn:
```sh
yarn add @babel/plugin-syntax-record-and-tuple --dev
```

View File

@@ -0,0 +1,23 @@
{
"name": "@babel/plugin-syntax-record-and-tuple",
"version": "7.7.4",
"description": "Allow parsing of records and tuples.",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-record-and-tuple",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "lib/index.js",
"keywords": [
"babel-plugin"
],
"dependencies": {
"@babel/helper-plugin-utils": "^7.0.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.0"
}
}

View File

@@ -0,0 +1,18 @@
import { declare } from "@babel/helper-plugin-utils";
export default declare((api, options) => {
api.assertVersion(7);
return {
name: "syntax-record-and-tuple",
manipulateOptions(opts, parserOpts) {
opts.generatorOpts.recordAndTupleSyntaxType = options.syntaxType;
parserOpts.plugins.push([
"recordAndTuple",
{ syntaxType: options.syntaxType },
]);
},
};
});