Skip to content
This repository was archived by the owner on Jun 22, 2023. It is now read-only.

Commit c431575

Browse files
committedJan 5, 2021
[Bugfix] Fix infinite recursion when emitting a named, implicit intersection schema (fix bcherny#309)
1 parent 82f1159 commit c431575

File tree

6 files changed

+1200
-8
lines changed

6 files changed

+1200
-8
lines changed
 

‎CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
- Add `export let only=true` to a test in test/e2e to just run that test
1010
- Add `export let exclude=true` to a test (or, add `.ignore` to its filename) in test/e2e to not run that test
1111
- To debug a test, with breakpoints:
12-
1. Install [node-inspector](https://www.npmjs.com/package/node-inspector)
13-
2. Run `node-debug ./node_modules/ava/profile.js ./dist/test/test.js`
12+
1. Run `npm run pretest`
13+
2. Follow the instructions [here](https://github.com/avajs/ava/blob/master/docs/recipes/debugging-with-vscode.md) for VSCode, [here](https://github.com/avajs/ava/blob/master/docs/recipes/debugging-with-webstorm.md) for Webstorm, or [here](https://github.com/avajs/ava/blob/master/docs/recipes/debugging-with-chrome-devtools.md) for Chrome Devtools

‎src/parser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
SchemaSchema,
2424
SchemaType
2525
} from './types/JSONSchema'
26-
import {generateName, log, maybeStripDefault} from './utils'
26+
import {generateName, log, maybeStripDefault, maybeStripNameHints} from './utils'
2727

2828
export type Processed = Map<LinkedJSONSchema, Map<SchemaType, AST>>
2929

@@ -66,7 +66,7 @@ export function parse(
6666
ast.params = types.map(type =>
6767
// We hoist description (for comment) and id/title (for standaloneName)
6868
// to the parent intersection type, so we remove it from the children.
69-
parseAsTypeWithCache(omit(schema, 'description', 'id', 'title'), type, options, keyName, processed, usedNames)
69+
parseAsTypeWithCache(maybeStripNameHints(schema), type, options, keyName, processed, usedNames)
7070
)
7171

7272
log('blue', 'parser', 'Types:', types, 'Input:', schema, 'Output:', ast)

‎src/utils.ts

+20
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,23 @@ export function maybeStripDefault(schema: LinkedJSONSchema): LinkedJSONSchema {
341341
delete schema.default
342342
return schema
343343
}
344+
345+
/**
346+
* Removes the schema's `id`, `name`, and `description` properties
347+
* if they exist.
348+
* Useful when parsing intersections.
349+
*
350+
* Mutates `schema`.
351+
*/
352+
export function maybeStripNameHints(schema: JSONSchema): JSONSchema {
353+
if ('description' in schema) {
354+
delete schema.description
355+
}
356+
if ('id' in schema) {
357+
delete schema.id
358+
}
359+
if ('name' in schema) {
360+
delete schema.name
361+
}
362+
return schema
363+
}

‎test/__snapshots__/test/test.ts.md

+466-4
Large diffs are not rendered by default.

‎test/__snapshots__/test/test.ts.snap

3.94 KB
Binary file not shown.

‎test/e2e/realWorld.schemaStore.1.ts

+710
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
This repository has been archived.