Skip to content

Commit aa5b915

Browse files
committed
Add disclaimiers why functions can only be used in an export context
1 parent adad5e3 commit aa5b915

File tree

1 file changed

+14
-0
lines changed
  • packages/nextjs/src/config/loaders

1 file changed

+14
-0
lines changed

packages/nextjs/src/config/loaders/ast.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,19 @@ export function hasDefaultExport(ast: AST): boolean {
360360
*
361361
* - `"...restElemet1"` --> `"restElement1"`
362362
* - `"...restElemet2"` --> `"restElement2"`
363+
*
364+
* DISCLAIMER: This function only correcly extracts the name of `RestElements` in the context of export statements.
365+
* Using this for `RestElements` outside of exports would require us to handle more edgecases. Hence the "Export" in
366+
* this function's name.
363367
*/
364368
function getExportIdentifiersFromRestElement(restElement: jscsTypes.RestElement): string[] {
365369
// This function returns an array instead of `string | undefined` for convenience since we exclusively use the return
366370
// value with `array.push()` in other functions in this file.
367371
return Identifier.check(restElement.argument) ? [restElement.argument.name] : [];
368372
}
369373

374+
const asdf = { ...({ a: 1 } || { b: 2 }) };
375+
370376
/**
371377
* Extracts all identifier names (`'constName'`) from an destructuringassignment'sArrayPattern (the `[constName]` in`const [constName] = [1]`).
372378
*
@@ -383,6 +389,10 @@ function getExportIdentifiersFromRestElement(restElement: jscsTypes.RestElement)
383389
* `[{ foo: name1 }, [{ bar: [name2]}, name3]]`
384390
*
385391
* Applying this function to this `ArrayPattern` will return the following: `["name1", "name2", "name3"]`
392+
*
393+
* DISCLAIMER: This function only correcly extracts identifiers of `ArrayPatterns` in the context of export statements.
394+
* Using this for `ArrayPattern` outside of exports would require us to handle more edgecases. Hence the "Export" in
395+
* this function's name.
386396
*/
387397
function getExportIdentifiersFromArrayPattern(arrayPattern: jscsTypes.ArrayPattern): string[] {
388398
const identifiers: string[] = [];
@@ -412,6 +422,10 @@ function getExportIdentifiersFromArrayPattern(arrayPattern: jscsTypes.ArrayPatte
412422
* Example:
413423
* export const { foo: [name1], bar: { baz: [{ quux: name2 }], ...name3 }} = { foo: [1], bar: { baz: [{ quux: 3 }]} };
414424
* --> ["name1", "name2", "name3"]
425+
*
426+
* DISCLAIMER: This function only correcly extracts identifiers of `ObjectPatterns` in the context of export statements.
427+
* Using this for `ObjectPatterns` outside of exports would require us to handle more edgecases. Hence the "Export" in
428+
* this function's name.
415429
*/
416430
function getExportIdentifiersFromObjectPattern(objectPatternNode: jscsTypes.ObjectPattern): string[] {
417431
const identifiers: string[] = [];

0 commit comments

Comments
 (0)