fix(tsc-wrapped): skip collecting metadata for default functions
Fixes: #17518
This commit is contained in:
parent
8c89cc4fc5
commit
46ddf501a9
@ -377,7 +377,7 @@ export class MetadataCollector {
|
|||||||
// Record functions that return a single value. Record the parameter
|
// Record functions that return a single value. Record the parameter
|
||||||
// names substitution will be performed by the StaticReflector.
|
// names substitution will be performed by the StaticReflector.
|
||||||
const functionDeclaration = <ts.FunctionDeclaration>node;
|
const functionDeclaration = <ts.FunctionDeclaration>node;
|
||||||
if (isExported(functionDeclaration)) {
|
if (isExported(functionDeclaration) && functionDeclaration.name) {
|
||||||
if (!metadata) metadata = {};
|
if (!metadata) metadata = {};
|
||||||
const name = exportedName(functionDeclaration);
|
const name = exportedName(functionDeclaration);
|
||||||
const maybeFunc = maybeGetSimpleFunction(functionDeclaration);
|
const maybeFunc = maybeGetSimpleFunction(functionDeclaration);
|
||||||
|
@ -634,10 +634,6 @@ describe('Collector', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('with interpolations', () => {
|
describe('with interpolations', () => {
|
||||||
function createSource(text: string): ts.SourceFile {
|
|
||||||
return ts.createSourceFile('', text, ts.ScriptTarget.Latest, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
function e(expr: string, prefix?: string) {
|
function e(expr: string, prefix?: string) {
|
||||||
const source = createSource(`${prefix || ''} export let value = ${expr};`);
|
const source = createSource(`${prefix || ''} export let value = ${expr};`);
|
||||||
const metadata = collector.getMetadata(source);
|
const metadata = collector.getMetadata(source);
|
||||||
@ -821,17 +817,53 @@ describe('Collector', () => {
|
|||||||
|
|
||||||
describe('regerssion', () => {
|
describe('regerssion', () => {
|
||||||
it('should be able to collect a short-hand property value', () => {
|
it('should be able to collect a short-hand property value', () => {
|
||||||
const source = ts.createSourceFile(
|
const source = createSource(`
|
||||||
'', `
|
|
||||||
const children = { f1: 1 };
|
const children = { f1: 1 };
|
||||||
export const r = [
|
export const r = [
|
||||||
{path: ':locale', children}
|
{path: ':locale', children}
|
||||||
];
|
];
|
||||||
`,
|
`);
|
||||||
ts.ScriptTarget.Latest, true);
|
|
||||||
const metadata = collector.getMetadata(source);
|
const metadata = collector.getMetadata(source);
|
||||||
expect(metadata.metadata).toEqual({r: [{path: ':locale', children: {f1: 1}}]});
|
expect(metadata.metadata).toEqual({r: [{path: ':locale', children: {f1: 1}}]});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// #17518
|
||||||
|
it('should skip a default function', () => {
|
||||||
|
const source = createSource(`
|
||||||
|
export default function () {
|
||||||
|
|
||||||
|
const mainRoutes = [
|
||||||
|
{name: 'a', abstract: true, component: 'main'},
|
||||||
|
|
||||||
|
{name: 'a.welcome', url: '/welcome', component: 'welcome'}
|
||||||
|
];
|
||||||
|
|
||||||
|
return mainRoutes;
|
||||||
|
|
||||||
|
}`);
|
||||||
|
const metadata = collector.getMetadata(source);
|
||||||
|
expect(metadata).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should skip a named default export', () => {
|
||||||
|
const source = createSource(`
|
||||||
|
function mainRoutes() {
|
||||||
|
|
||||||
|
const mainRoutes = [
|
||||||
|
{name: 'a', abstract: true, component: 'main'},
|
||||||
|
|
||||||
|
{name: 'a.welcome', url: '/welcome', component: 'welcome'}
|
||||||
|
];
|
||||||
|
|
||||||
|
return mainRoutes;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
exports = foo;
|
||||||
|
`);
|
||||||
|
const metadata = collector.getMetadata(source);
|
||||||
|
expect(metadata).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function override(fileName: string, content: string) {
|
function override(fileName: string, content: string) {
|
||||||
@ -1321,3 +1353,7 @@ const FILES: Directory = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createSource(text: string): ts.SourceFile {
|
||||||
|
return ts.createSourceFile('', text, ts.ScriptTarget.Latest, true);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user