Skip to content

Commit

Permalink
Type-safe ParseErrors (#14320)
Browse files Browse the repository at this point in the history
* Flow ParseError version.

Reviewed by @tolmasky.

* Begin updating everything.

Reviewed by @tolmasky.

* Convert more.

Reviewed by @tolmasky.

* Add more.

Reviewed by @tolmasky.

* Fix.

Reviewed by @tolmasky.

* Just switch everything to exact types.

Reviewed by @tolmasky.

* Style fixes.

Reviewed by @tolmasky.

* Fix remaining style issues and remove unecessary dry-error-messages.

Reviewed by @tolmasky.

* Don't use enums and address more issues.

Reviewed by @tolmasky.

* More fixes.

Reviewed by @tolmasky.

* Workaround for import situation.

Reviewed by @tolmasky.

* Fix a bunch of errors messages.

Reviewed by @tolmasky.

* Fix some flow stuff.

Reviewed by @tolmasky.

* Add a way to specify code.

Reviewed by @tolmasky.

* Fix lint errors.

Reviewed by @tolmasky.

* Fix Flow errors.

Reviewed by @tolmasky.

Another Flow things.

Reviewed by @tolmasky.

Fix Flow error.

Reviewed by @tolmasky.

Fix flow errors.

Reviewed by @tolmasky.

Fix flow error.

Reviewed by @tolmasky.

* See if this gets the name right.

Reviewed by @tolmasky.

* Add comments to raise and raiseOverwrite.

Reviewed by @tolmasky.

* Remove forward declaration.

Reviewed by @tolmasky.

* Change option to be kind.

Reviewed by @tolmasky.

* Fix for ambient context not being respected in variable declarations.

Reviewed by @tolmasky.

* Make IllegalBreakContinue based on type.

Reviewed by @tolmasky.

* Begin moving checkLVal to type-based system instead of contextDescription-based system, and fix let error in the process as well.

Reviewed by @tolmasky.

* Switch to isValidLVal.

Reviewed by @tolmasky.

* Don't use checkLVal for class names.

Reviewed by @tolmasky.

* Fix some Flow errors.

Reviewed by @tolmasky.

* Temporary fix for Flow error.

Reviewed by @tolmasky.

* Remove unused stuff.

Reviewed by @tolmasky.

* Try this.

Reviewed by @tolmasky.

* Don't use Object.fromEntries.

Reviewed by @tolmasky.

* Fix linter error.

Reviewed by @tolmasky.

* Fix for SyntaxError.

Reviewed by @tolmasky.

* Add TS1039 Initializers are not allowed in ambient contexts. to error-codes.js.

Reviewed by @tolmasky.

* Add TS1155 'const' declarations must be initialized.

Reviewed by @tolmasky.

* Allow consts with literals.

Reviewed by @tolmasky.

* Add enum support.

Reviewed by @tolmasky.

* Add filename to test runner to correctly identify .d.ts files.

Reviewed by @tolmasky.

* Only ignore reserved words in ambient contexts. Parse interface in parseStatementContent. Fix enums.

Reviewed by @tolmasky.

* Fix simple parameter error.

Reviewed by @tolmasky.

* Type references should allow reserved words (I believe we were just getting away with the fact that we turned reserved words off before).

Reviewed by @tolmasky.

* Allow import and export in TypeScript regardless of module or script.

Reviewed by @tolmasky.

* Fix declare enum and interface and reorganize the code a bit.

Reviewed by @tolmasky.

* Fix for keywords in export as.

Reviewed by @tolmasky.

* Fix reserved words in import types.

Reviewed by @tolmasky.

* Rename files.

Reviewed by @tolmasky.

* Add 1

* Remove files form allowlist that no longer need to be there.

Reviewed by @tolmasky.

* Parse as separate files and switch to only using error codes.

Reviewed by @tolmasky.

* Fix reading files with different encodings.

Reviewed by @tolmasky.

* Fix outside tests.

Reviewed by @tolmasky.

* Change test to pass since typescript should allow import.

Reviewed by @tolmasky.

* Update tests that should fail.

Reviewed by @tolmasky.

* Add tests for complex let assignments.

Reviewed by @tolmasky.

* Choose a better name for these.

Reviewed by @tolmasky.

* Add tests for a number of left-hand side expressions.

Reviewed by @tolmasky.

* Change name to kind.

Reviewed by @tolmasky.

* Choose better parameter names for these errors.

Reviewed by @tolmasky.

* Use error credentials and error details.

Reviewed by @tolmasky.

* Fix some names and add comments.

Reviewed by @tolmasky.

* Get rid of unused option.

Reviewed by @tolmasky.

* Better names.

Reviewed by @tolmasky.

* Split out pipeline errors and choose better names.

Reviewed by @tolmasky.

* Clean up LVal stuff.

reviewed by @tolmasky.

* Use "unambiguous" to determine whether to parse typescript tests as module or script, and stop always allowing imports in Typescript.

Reviewed by @tolmasky.

* Revert test to previous state.

Reviewed by @tolmasky.

* Better name for this.

Reviewed by @tolmasky.

* Add these back in.

Reviewed by @tolmasky.

* Add these.

Reviewed by @tolmasky.

* Fix flow errors and use toNodeDescription in more places.

Reviewed by @tolmasky.

* Rename LHSParent to LValAncestor.

Reviewed by @tolmasky.

* Add ParseError.clone and change symbol name to DefaultMessage from NoMessage.

Reviewed by @tolmasky.

* Change name to identifierName in a bunch of places.

Reviewed by @tolmasky.

* Fix for using type.

Reviewed by @tolmasky.

* Better names.

Reviewed by @tolmasky.

* Clean up API and add comments.

Reviewed by @tolmasky.

* Change name.

Reviewed by @tolmasky.

* Better names.

Reviewed by @tolmasky.

* Minor comment fix.

Reviewed by @tolmasky.

* Remove no longer used method.

Reviewed by @tolmasky.

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

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

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

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* Minor grammar changes to comments.

Reviewed by @tolmasky.

* Use trim instead of slice(0, -1).

Reviewed by @tolmasky.

* Add a comment to explain the tagged template stuff.

Reviewed by @tolmasky.

* Use maxArgumentCount.

Reviewed by @tolmasky.

* Don't allow UpdateExpression without prefix.

Reviewed by @tolmasky.

* Add tds test for no-initializer.

Reviewed by @tolmasky.

* Make this test test ASI and not const initializers.

Reviewed by @tolmasky.

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

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* Change template string to normal string and remove default.

Reviewed by @tolmasky.

* Get rid of ParseError class and use SyntaxErrors instead.

Reviewed by @tolmasky.

* Update packages/babel-parser/src/parse-error.js

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>

* Remove this comment since we don't need this argument anymore.

Reviewed by @tolmasky.

* Use this in toMessage and restore clone method.

Reviewed by @tolmasky.

* Make sure pos and missingPlugin are enumerable.

Reviewed by @tolmasky.

* Make typescript tests faster by checking the bom manually.

Reviewed by @tolmasky.

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

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* Update packages/babel-parser/src/plugins/estree.js

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* Update packages/babel-parser/src/plugins/typescript/index.js

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* Update packages/babel-parser/src/plugins/typescript/index.js

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>

* Clarify const enum initialization comment.

Reviewed by @tolmasky.

* Fix Flow being angry because __proto__: null makes it think that the return type can be null.

Reviewed by @tolmasky.

* Don't automatically set DTS on the typescript plugin based on filename.

Reviewed by @tolmasky.

* Fix duplicated export error.

Reviewed by @tolmasky.

Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
  • Loading branch information
3 people committed Mar 8, 2022
1 parent 4f80f5c commit 9ba894c
Show file tree
Hide file tree
Showing 87 changed files with 3,263 additions and 2,973 deletions.
17 changes: 0 additions & 17 deletions .eslintrc.cjs
@@ -1,7 +1,5 @@
"use strict";

const path = require("path");

const cjsGlobals = ["__dirname", "__filename", "require", "module", "exports"];

const testFiles = [
Expand Down Expand Up @@ -105,21 +103,6 @@ module.exports = {
eqeqeq: ["error", "always", { null: "ignore" }],
},
},
{
files: ["packages/babel-parser/src/**/*.{js,ts}"],
rules: {
"@babel/development-internal/dry-error-messages": [
"error",
{
errorModule: path.resolve(
__dirname,
"packages/babel-parser/src/parser/error.js"
),
},
],
"@babel/development-internal/report-error-message-format": "error",
},
},
{
files: ["packages/babel-helpers/src/helpers/**.js"],
rules: {
Expand Down
45 changes: 0 additions & 45 deletions eslint/babel-eslint-plugin-development-internal/README.md
Expand Up @@ -24,51 +24,6 @@ The plugin can be loaded in your `.eslintrc.*` configuration file as follows: (n

## Rules

### `@babel/development-internal/dry-error-messages`

Intended for use in `packages/babel-parser/src/**/*`. When enabled, this rule warns when `this.raise()` invocations raise errors that are not imported from a designated error module.

Accepts an object configuration option:

```ts
{
errorModule: string
}
```

`errorModule` (required): The rule expects either an absolute path or a module name (for a module in `node_modules`). Please note that the rule will not check anything if` errorModule` is not given.

Example configuration:

```js
{
rules: {
"@babel/development-internal/dry-error-messages": [
"error",
{
errorModule: "@babel/shared-error-messages"
}
]
}
}
```
and
```js
{
rules: {
"@babel/development-internal/dry-error-messages": [
"error",
{
errorModule: path.resolve(
__dirname,
"packages/shared-error-messages/lib/index.js"
)
}
]
}
}
```

### `@babel/development-internal/report-error-message-format`

This rule is inspired by https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/report-message-format.md.
Expand Down
2 changes: 0 additions & 2 deletions eslint/babel-eslint-plugin-development-internal/src/index.cjs
@@ -1,8 +1,6 @@
const dryErrorMessages = require("./rules/dry-error-messages.cjs");
const reportErrorMessageFormat = require("./rules/report-error-message-format.cjs");

const rules = {
"dry-error-messages": dryErrorMessages,
"report-error-message-format": reportErrorMessageFormat,
};

Expand Down

This file was deleted.

0 comments on commit 9ba894c

Please sign in to comment.