mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 12:53:27 -05:00
add transformer for emit add property to default export
This commit is contained in:
@@ -1008,7 +1008,43 @@ namespace ts {
|
||||
return createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([varDecl]));
|
||||
});
|
||||
const namespaceDecl = createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input, isPrivate), input.name!, createModuleBlock(declarations), NodeFlags.Namespace);
|
||||
return [clean, namespaceDecl];
|
||||
|
||||
if (!hasModifier(clean, ModifierFlags.ExportDefault)) {
|
||||
return [clean, namespaceDecl];
|
||||
}
|
||||
|
||||
const modifierFlags = (getModifierFlags(clean) & ~ModifierFlags.ExportDefault) | ModifierFlags.Ambient;
|
||||
const cleanDeclaration = updateFunctionDeclaration(
|
||||
clean,
|
||||
/*decorators*/ undefined,
|
||||
createModifiersFromModifierFlags(modifierFlags),
|
||||
/*asteriskToken*/ undefined,
|
||||
clean.name,
|
||||
clean.typeParameters,
|
||||
clean.parameters,
|
||||
clean.type,
|
||||
/*body*/ undefined
|
||||
);
|
||||
|
||||
const namespaceDeclaration = updateModuleDeclaration(
|
||||
namespaceDecl,
|
||||
/*decorators*/ undefined,
|
||||
createModifiersFromModifierFlags(modifierFlags),
|
||||
input.name!,
|
||||
createModuleBlock(declarations)
|
||||
);
|
||||
|
||||
const exportDefaultDeclaration = createExportAssignment(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/undefined,
|
||||
/*isExportEquals*/false,
|
||||
clean.name!
|
||||
);
|
||||
|
||||
resultHasExternalModuleIndicator = true;
|
||||
resultHasScopeMarker = true;
|
||||
|
||||
return [cleanDeclaration, namespaceDeclaration, exportDefaultDeclaration];
|
||||
}
|
||||
else {
|
||||
return clean;
|
||||
@@ -1153,6 +1189,8 @@ namespace ts {
|
||||
return preserveJsDoc(updateEnumMember(m, m.name, constValue !== undefined ? createLiteral(constValue) : undefined), m);
|
||||
}))));
|
||||
}
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return;
|
||||
}
|
||||
// Anything left unhandled is an error, so this should be unreachable
|
||||
return Debug.assertNever(input, `Unhandled top-level node in declaration emit: ${(ts as any).SyntaxKind[(input as any).kind]}`);
|
||||
|
||||
@@ -3435,7 +3435,8 @@ namespace ts {
|
||||
| ModuleDeclaration
|
||||
| TypeAliasDeclaration
|
||||
| InterfaceDeclaration
|
||||
| EnumDeclaration;
|
||||
| EnumDeclaration
|
||||
| ExportAssignment;
|
||||
|
||||
/* @internal */
|
||||
export interface SymbolVisibilityResult {
|
||||
|
||||
24
tests/baselines/reference/exportDefaultNamespace.js
Normal file
24
tests/baselines/reference/exportDefaultNamespace.js
Normal file
@@ -0,0 +1,24 @@
|
||||
//// [exportDefaultNamespace.ts]
|
||||
export default function someFunc() {
|
||||
return 'hello!';
|
||||
}
|
||||
|
||||
someFunc.someProp = 'yo';
|
||||
|
||||
|
||||
//// [exportDefaultNamespace.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
function someFunc() {
|
||||
return 'hello!';
|
||||
}
|
||||
exports["default"] = someFunc;
|
||||
someFunc.someProp = 'yo';
|
||||
|
||||
|
||||
//// [exportDefaultNamespace.d.ts]
|
||||
declare function someFunc(): string;
|
||||
declare namespace someFunc {
|
||||
var someProp: string;
|
||||
}
|
||||
export default someFunc;
|
||||
12
tests/baselines/reference/exportDefaultNamespace.symbols
Normal file
12
tests/baselines/reference/exportDefaultNamespace.symbols
Normal file
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/conformance/declarationEmit/exportDefaultNamespace.ts ===
|
||||
export default function someFunc() {
|
||||
>someFunc : Symbol(someFunc, Decl(exportDefaultNamespace.ts, 0, 0), Decl(exportDefaultNamespace.ts, 2, 1))
|
||||
|
||||
return 'hello!';
|
||||
}
|
||||
|
||||
someFunc.someProp = 'yo';
|
||||
>someFunc.someProp : Symbol(someFunc.someProp, Decl(exportDefaultNamespace.ts, 2, 1))
|
||||
>someFunc : Symbol(someFunc, Decl(exportDefaultNamespace.ts, 0, 0), Decl(exportDefaultNamespace.ts, 2, 1))
|
||||
>someProp : Symbol(someFunc.someProp, Decl(exportDefaultNamespace.ts, 2, 1))
|
||||
|
||||
15
tests/baselines/reference/exportDefaultNamespace.types
Normal file
15
tests/baselines/reference/exportDefaultNamespace.types
Normal file
@@ -0,0 +1,15 @@
|
||||
=== tests/cases/conformance/declarationEmit/exportDefaultNamespace.ts ===
|
||||
export default function someFunc() {
|
||||
>someFunc : typeof someFunc
|
||||
|
||||
return 'hello!';
|
||||
>'hello!' : "hello!"
|
||||
}
|
||||
|
||||
someFunc.someProp = 'yo';
|
||||
>someFunc.someProp = 'yo' : "yo"
|
||||
>someFunc.someProp : string
|
||||
>someFunc : typeof someFunc
|
||||
>someProp : string
|
||||
>'yo' : "yo"
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// @declaration: true
|
||||
|
||||
export default function someFunc() {
|
||||
return 'hello!';
|
||||
}
|
||||
|
||||
someFunc.someProp = 'yo';
|
||||
Reference in New Issue
Block a user