Skip to content

Commit

Permalink
Refactor error codes in the TS plugin (#42585)
Browse files Browse the repository at this point in the history
Small code refactoring.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
shuding committed Nov 7, 2022
1 parent 3e2e39c commit b1932b0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/next/server/next-typescript.ts
Expand Up @@ -29,6 +29,13 @@ const DISALLOWED_SERVER_REACT_APIS: string[] = [

const ALLOWED_EXPORTS = ['config', 'generateStaticParams']

const NEXT_TS_ERRORS = {
INVALID_SERVER_API: 71001,
INVALID_ENTRY_EXPORT: 71002,
INVALID_OPTION_VALUE: 71003,
MISPLACED_CLIENT_ENTRY: 71004,
}

const API_DOCS: Record<
string,
{
Expand Down Expand Up @@ -496,7 +503,7 @@ export function createTSPlugin(modules: {
prior.push({
file: source,
category: ts.DiagnosticCategory.Error,
code: 71004,
code: NEXT_TS_ERRORS.MISPLACED_CLIENT_ENTRY,
...e,
})
isClientEntry = false
Expand All @@ -519,7 +526,7 @@ export function createTSPlugin(modules: {
prior.push({
file: source,
category: ts.DiagnosticCategory.Error,
code: 71001,
code: NEXT_TS_ERRORS.INVALID_SERVER_API,
messageText: `"${name}" is not allowed in Server Components.`,
start: element.name.getStart(),
length:
Expand All @@ -546,7 +553,7 @@ export function createTSPlugin(modules: {
prior.push({
file: source,
category: ts.DiagnosticCategory.Error,
code: 71002,
code: NEXT_TS_ERRORS.INVALID_ENTRY_EXPORT,
messageText: `"${name.text}" is not a valid Next.js entry export value.`,
start: name.getStart(),
length: name.getEnd() - name.getStart(),
Expand Down Expand Up @@ -620,7 +627,7 @@ export function createTSPlugin(modules: {
prior.push({
file: source,
category: ts.DiagnosticCategory.Error,
code: 71003,
code: NEXT_TS_ERRORS.INVALID_OPTION_VALUE,
messageText:
errorMessage ||
`"${displayedValue}" is not a valid value for the "${name.text}" option.`,
Expand Down

0 comments on commit b1932b0

Please sign in to comment.