@angular/core
Advanced tools
Comparing version 19.0.0 to 19.0.1
{ | ||
"name": "@angular/core", | ||
"version": "19.0.0", | ||
"version": "19.0.1", | ||
"description": "Angular - the core framework", | ||
@@ -5,0 +5,0 @@ "author": "angular", |
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -4,0 +4,0 @@ * License: MIT |
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -4,0 +4,0 @@ * License: MIT |
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -4,0 +4,0 @@ * License: MIT |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -14,7 +14,7 @@ * License: MIT | ||
var project_tsconfig_paths = require('./project_tsconfig_paths-e9ccccbf.js'); | ||
var compiler_host = require('./compiler_host-d642e87e.js'); | ||
var compiler_host = require('./compiler_host-087c5caa.js'); | ||
var ts = require('typescript'); | ||
var imports = require('./imports-4ac08251.js'); | ||
require('@angular-devkit/core'); | ||
require('./checker-e3da3b0a.js'); | ||
require('./checker-3cbc9cc1.js'); | ||
require('os'); | ||
@@ -21,0 +21,0 @@ require('fs'); |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -5,0 +5,0 @@ * License: MIT |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -13,3 +13,3 @@ * License: MIT | ||
var p = require('path'); | ||
var compiler_host = require('./compiler_host-d642e87e.js'); | ||
var compiler_host = require('./compiler_host-087c5caa.js'); | ||
var ts = require('typescript'); | ||
@@ -19,3 +19,3 @@ var nodes = require('./nodes-0e7d45ca.js'); | ||
var leading_space = require('./leading_space-d190b83b.js'); | ||
require('./checker-e3da3b0a.js'); | ||
require('./checker-3cbc9cc1.js'); | ||
require('os'); | ||
@@ -151,3 +151,3 @@ require('fs'); | ||
} | ||
declaration.body.forEachChild(function walk(node) { | ||
const analyze = (node) => { | ||
// Don't descend into statements that were removed already. | ||
@@ -158,3 +158,3 @@ if (ts__default["default"].isStatement(node) && removedStatements.has(node)) { | ||
if (!ts__default["default"].isIdentifier(node) || !topLevelParameterNames.has(node.text)) { | ||
node.forEachChild(walk); | ||
node.forEachChild(analyze); | ||
return; | ||
@@ -178,3 +178,9 @@ } | ||
}); | ||
}; | ||
declaration.parameters.forEach((param) => { | ||
if (param.initializer) { | ||
analyze(param.initializer); | ||
} | ||
}); | ||
declaration.body.forEachChild(analyze); | ||
for (const param of topLevelParameters) { | ||
@@ -218,2 +224,37 @@ if (!accessedTopLevelParameters.has(param)) { | ||
} | ||
/** | ||
* Determines if a specific parameter has references to other parameters. | ||
* @param param Parameter to check. | ||
* @param allParameters All parameters of the containing function. | ||
* @param localTypeChecker Type checker scoped to the current file. | ||
*/ | ||
function parameterReferencesOtherParameters(param, allParameters, localTypeChecker) { | ||
// A parameter can only reference other parameters through its initializer. | ||
if (!param.initializer || allParameters.length < 2) { | ||
return false; | ||
} | ||
const paramNames = new Set(); | ||
for (const current of allParameters) { | ||
if (current !== param && ts__default["default"].isIdentifier(current.name)) { | ||
paramNames.add(current.name.text); | ||
} | ||
} | ||
let result = false; | ||
const analyze = (node) => { | ||
if (ts__default["default"].isIdentifier(node) && paramNames.has(node.text) && !isAccessedViaThis(node)) { | ||
const symbol = localTypeChecker.getSymbolAtLocation(node); | ||
const referencesOtherParam = symbol?.declarations?.some((decl) => { | ||
return allParameters.includes(decl); | ||
}); | ||
if (referencesOtherParam) { | ||
result = true; | ||
} | ||
} | ||
if (!result) { | ||
node.forEachChild(analyze); | ||
} | ||
}; | ||
analyze(param.initializer); | ||
return result; | ||
} | ||
/** Checks whether a parameter node declares a property on its class. */ | ||
@@ -596,3 +637,4 @@ function parameterDeclaresProperty(node) { | ||
const usedInConstructor = !unusedParameters.has(param); | ||
migrateParameter(param, options, localTypeChecker, printer, tracker, superCall, usedInSuper, usedInConstructor, memberIndentation, innerIndentation, prependToConstructor, prependToClass, afterSuper); | ||
const usesOtherParams = parameterReferencesOtherParameters(param, constructor.parameters, localTypeChecker); | ||
migrateParameter(param, options, localTypeChecker, printer, tracker, superCall, usedInSuper, usedInConstructor, usesOtherParams, memberIndentation, innerIndentation, prependToConstructor, prependToClass, afterSuper); | ||
} | ||
@@ -607,3 +649,3 @@ // Delete all of the constructor overloads since below we're either going to | ||
} | ||
if (canRemoveConstructor(options, constructor, removedStatementCount, superCall)) { | ||
if (canRemoveConstructor(options, constructor, removedStatementCount, prependToConstructor, superCall)) { | ||
// Drop the constructor if it was empty. | ||
@@ -618,3 +660,11 @@ removedMembers.add(constructor); | ||
if (prependToConstructor.length > 0) { | ||
tracker.insertText(sourceFile, (firstConstructorStatement || innerReference).getFullStart(), `\n${prependToConstructor.join('\n')}\n`); | ||
if (firstConstructorStatement || | ||
(innerReference !== constructor && | ||
innerReference.getStart() >= constructor.getStart() && | ||
innerReference.getEnd() <= constructor.getEnd())) { | ||
tracker.insertText(sourceFile, (firstConstructorStatement || innerReference).getFullStart(), `\n${prependToConstructor.join('\n')}\n`); | ||
} | ||
else { | ||
tracker.insertText(sourceFile, constructor.body.getStart() + 1, `\n${prependToConstructor.map((p) => innerIndentation + p).join('\n')}\n${innerIndentation}`); | ||
} | ||
} | ||
@@ -674,3 +724,3 @@ } | ||
*/ | ||
function migrateParameter(node, options, localTypeChecker, printer, tracker, superCall, usedInSuper, usedInConstructor, memberIndentation, innerIndentation, prependToConstructor, propsToAdd, afterSuper) { | ||
function migrateParameter(node, options, localTypeChecker, printer, tracker, superCall, usedInSuper, usedInConstructor, usesOtherParams, memberIndentation, innerIndentation, prependToConstructor, propsToAdd, afterSuper) { | ||
if (!ts__default["default"].isIdentifier(node.name)) { | ||
@@ -684,2 +734,5 @@ return; | ||
if (declaresProp) { | ||
// We can't initialize the property if it's referenced within a `super` call or it references | ||
// other parameters. See the logic further below for the initialization. | ||
const canInitialize = !usedInSuper && !usesOtherParams; | ||
const prop = ts__default["default"].factory.createPropertyDeclaration(cloneModifiers(node.modifiers?.filter((modifier) => { | ||
@@ -692,6 +745,3 @@ // Strip out the DI decorators, as well as `public` which is redundant. | ||
? undefined | ||
: node.questionToken, | ||
// We can't initialize the property if it's referenced within a `super` call. | ||
// See the logic further below for the initialization. | ||
usedInSuper ? node.type : undefined, usedInSuper ? undefined : ts__default["default"].factory.createIdentifier(PLACEHOLDER)); | ||
: node.questionToken, canInitialize ? undefined : node.type, canInitialize ? ts__default["default"].factory.createIdentifier(PLACEHOLDER) : undefined); | ||
propsToAdd.push(memberIndentation + | ||
@@ -729,2 +779,11 @@ replaceNodePlaceholder(node.getSourceFile(), prop, replacementCall, printer)); | ||
} | ||
else if (usesOtherParams && declaresProp) { | ||
const toAdd = `${innerIndentation}this.${name} = ${replacementCall};`; | ||
if (superCall === null) { | ||
prependToConstructor.push(toAdd); | ||
} | ||
else { | ||
afterSuper.push(toAdd); | ||
} | ||
} | ||
} | ||
@@ -816,2 +875,6 @@ /** | ||
} | ||
// If the parameter is initialized, add the initializer as a fallback. | ||
if (param.initializer) { | ||
expression = ts__default["default"].factory.createBinaryExpression(expression, ts__default["default"].SyntaxKind.QuestionQuestionToken, param.initializer); | ||
} | ||
return replaceNodePlaceholder(param.getSourceFile(), expression, injectedType, printer); | ||
@@ -973,6 +1036,7 @@ } | ||
* @param removedStatementCount Number of statements that were removed by the migration. | ||
* @param prependToConstructor Statements that should be prepended to the constructor. | ||
* @param superCall Node representing the `super()` call within the constructor. | ||
*/ | ||
function canRemoveConstructor(options, constructor, removedStatementCount, superCall) { | ||
if (options.backwardsCompatibleConstructors) { | ||
function canRemoveConstructor(options, constructor, removedStatementCount, prependToConstructor, superCall) { | ||
if (options.backwardsCompatibleConstructors || prependToConstructor.length > 0) { | ||
return false; | ||
@@ -1057,2 +1121,3 @@ } | ||
tracker.removeNode(decl, true); | ||
removedMembers.add(decl); | ||
}); | ||
@@ -1059,0 +1124,0 @@ // If we added any hoisted properties, separate them visually with a new line. |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -5,0 +5,0 @@ * License: MIT |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -5,0 +5,0 @@ * License: MIT |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -13,7 +13,7 @@ * License: MIT | ||
var project_tsconfig_paths = require('./project_tsconfig_paths-e9ccccbf.js'); | ||
var combine_units = require('./combine_units-2adebceb.js'); | ||
var combine_units = require('./combine_units-c36a3065.js'); | ||
require('os'); | ||
var ts = require('typescript'); | ||
var checker = require('./checker-e3da3b0a.js'); | ||
var program = require('./program-f984ab63.js'); | ||
var checker = require('./checker-3cbc9cc1.js'); | ||
var program = require('./program-561595c4.js'); | ||
require('path'); | ||
@@ -20,0 +20,0 @@ require('@angular-devkit/core'); |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -14,7 +14,7 @@ * License: MIT | ||
var project_tsconfig_paths = require('./project_tsconfig_paths-e9ccccbf.js'); | ||
var compiler_host = require('./compiler_host-d642e87e.js'); | ||
var compiler_host = require('./compiler_host-087c5caa.js'); | ||
var ts = require('typescript'); | ||
var imports = require('./imports-4ac08251.js'); | ||
require('@angular-devkit/core'); | ||
require('./checker-e3da3b0a.js'); | ||
require('./checker-3cbc9cc1.js'); | ||
require('os'); | ||
@@ -21,0 +21,0 @@ require('fs'); |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -5,0 +5,0 @@ * License: MIT |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -14,7 +14,7 @@ * License: MIT | ||
var project_tsconfig_paths = require('./project_tsconfig_paths-e9ccccbf.js'); | ||
var compiler_host = require('./compiler_host-d642e87e.js'); | ||
var compiler_host = require('./compiler_host-087c5caa.js'); | ||
var ts = require('typescript'); | ||
var imports = require('./imports-4ac08251.js'); | ||
require('@angular-devkit/core'); | ||
require('./checker-e3da3b0a.js'); | ||
require('./checker-3cbc9cc1.js'); | ||
require('os'); | ||
@@ -74,30 +74,34 @@ require('fs'); | ||
let useExisting; | ||
let useFactory; | ||
let useFactoryCode; | ||
let useValue; | ||
let multi = false; | ||
for (const property of node.properties) { | ||
if (!ts__default["default"].isPropertyAssignment(property) || !ts__default["default"].isIdentifier(property.name)) { | ||
continue; | ||
if (ts__default["default"].isPropertyAssignment(property) && ts__default["default"].isIdentifier(property.name)) { | ||
switch (property.name.text) { | ||
case 'deps': | ||
if (ts__default["default"].isArrayLiteralExpression(property.initializer)) { | ||
deps = property.initializer.elements.map((el) => el.getText()); | ||
} | ||
break; | ||
case 'provide': | ||
initializerToken = property.initializer.getText(); | ||
break; | ||
case 'useExisting': | ||
useExisting = property.initializer; | ||
break; | ||
case 'useFactory': | ||
useFactoryCode = property.initializer.getText(); | ||
break; | ||
case 'useValue': | ||
useValue = property.initializer; | ||
break; | ||
case 'multi': | ||
multi = property.initializer.kind === ts__default["default"].SyntaxKind.TrueKeyword; | ||
break; | ||
} | ||
} | ||
switch (property.name.text) { | ||
case 'deps': | ||
if (ts__default["default"].isArrayLiteralExpression(property.initializer)) { | ||
deps = property.initializer.elements.map((el) => el.getText()); | ||
} | ||
break; | ||
case 'provide': | ||
initializerToken = property.initializer.getText(); | ||
break; | ||
case 'useExisting': | ||
useExisting = property.initializer; | ||
break; | ||
case 'useFactory': | ||
useFactory = property.initializer; | ||
break; | ||
case 'useValue': | ||
useValue = property.initializer; | ||
break; | ||
case 'multi': | ||
multi = property.initializer.kind === ts__default["default"].SyntaxKind.TrueKeyword; | ||
break; | ||
// Handle the `useFactory() {}` shorthand case. | ||
if (ts__default["default"].isMethodDeclaration(property) && property.name.getText() === 'useFactory') { | ||
const params = property.parameters.map((param) => param.getText()).join(', '); | ||
useFactoryCode = `(${params}) => ${property.body?.getText()}`; | ||
} | ||
@@ -124,3 +128,3 @@ } | ||
} | ||
if (useFactory) { | ||
if (useFactoryCode) { | ||
const args = deps.map((dep) => `inject(${dep})`); | ||
@@ -130,3 +134,6 @@ return { | ||
importInject: deps.length > 0, | ||
initializerCode: `(${useFactory.getText()})(${args.join(', ')})`, | ||
initializerCode: `() => { | ||
const initializerFn = (${useFactoryCode})(${args.join(', ')}); | ||
return initializerFn(); | ||
}`, | ||
}; | ||
@@ -133,0 +140,0 @@ } |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -14,10 +14,10 @@ * License: MIT | ||
var p = require('path'); | ||
var compiler_host = require('./compiler_host-d642e87e.js'); | ||
var compiler_host = require('./compiler_host-087c5caa.js'); | ||
var project_tsconfig_paths = require('./project_tsconfig_paths-e9ccccbf.js'); | ||
var ts = require('typescript'); | ||
require('./checker-e3da3b0a.js'); | ||
var checker = require('./checker-3cbc9cc1.js'); | ||
require('os'); | ||
require('@angular-devkit/core'); | ||
require('module'); | ||
require('url'); | ||
require('@angular-devkit/core'); | ||
@@ -55,19 +55,22 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
* @param node Class being checked. | ||
* @param reflector The reflection host to use. | ||
*/ | ||
function isStandaloneComponent(node) { | ||
const decorator = node.modifiers?.find((m) => m.kind === ts__default["default"].SyntaxKind.Decorator); | ||
if (!decorator) { | ||
function isStandaloneComponent(node, reflector) { | ||
const decorators = reflector.getDecoratorsOfDeclaration(node); | ||
if (decorators === null) { | ||
return false; | ||
} | ||
if (ts__default["default"].isCallExpression(decorator.expression)) { | ||
const arg = decorator.expression.arguments[0]; | ||
if (ts__default["default"].isObjectLiteralExpression(arg)) { | ||
const property = findLiteralProperty(arg, 'standalone'); | ||
if (property) { | ||
return property.initializer.getText() === 'true'; | ||
} | ||
else { | ||
return true; // standalone is true by default in v19 | ||
} | ||
const decorator = checker.findAngularDecorator(decorators, 'Component', false); | ||
if (decorator === undefined || decorator.args === null || decorator.args.length !== 1) { | ||
return false; | ||
} | ||
const arg = decorator.args[0]; | ||
if (ts__default["default"].isObjectLiteralExpression(arg)) { | ||
const property = findLiteralProperty(arg, 'standalone'); | ||
if (property) { | ||
return property.initializer.getText() === 'true'; | ||
} | ||
else { | ||
return true; // standalone is true by default in v19 | ||
} | ||
} | ||
@@ -166,2 +169,3 @@ return false; | ||
const typeChecker = program.getTypeChecker(); | ||
const reflector = new checker.TypeScriptReflectionHost(typeChecker); | ||
const printer = ts__default["default"].createPrinter(); | ||
@@ -173,3 +177,3 @@ const tracker = new compiler_host.ChangeTracker(printer); | ||
} | ||
const { skippedRoutes, migratedRoutes } = migrateRoutesArray(routeArraysToMigrate, typeChecker, tracker); | ||
const { skippedRoutes, migratedRoutes } = migrateRoutesArray(routeArraysToMigrate, typeChecker, reflector, tracker); | ||
return { | ||
@@ -246,3 +250,3 @@ pendingChanges: tracker.recordChanges().get(sourceFile) || [], | ||
/** Migrate a routes object standalone components to be lazy loaded. */ | ||
function migrateRoutesArray(routesArray, typeChecker, tracker) { | ||
function migrateRoutesArray(routesArray, typeChecker, reflector, tracker) { | ||
const migratedRoutes = []; | ||
@@ -254,3 +258,3 @@ const skippedRoutes = []; | ||
if (ts__default["default"].isObjectLiteralExpression(element)) { | ||
const { migratedRoutes: migrated, skippedRoutes: toBeSkipped, importsToRemove: toBeRemoved, } = migrateRoute(element, route, typeChecker, tracker); | ||
const { migratedRoutes: migrated, skippedRoutes: toBeSkipped, importsToRemove: toBeRemoved, } = migrateRoute(element, route, typeChecker, reflector, tracker); | ||
migratedRoutes.push(...migrated); | ||
@@ -271,3 +275,3 @@ skippedRoutes.push(...toBeSkipped); | ||
*/ | ||
function migrateRoute(element, route, typeChecker, tracker) { | ||
function migrateRoute(element, route, typeChecker, reflector, tracker) { | ||
const skippedRoutes = []; | ||
@@ -284,3 +288,3 @@ const migratedRoutes = []; | ||
if (ts__default["default"].isObjectLiteralExpression(childRoute)) { | ||
const { migratedRoutes: migrated, skippedRoutes: toBeSkipped, importsToRemove: toBeRemoved, } = migrateRoute(childRoute, route, typeChecker, tracker); | ||
const { migratedRoutes: migrated, skippedRoutes: toBeSkipped, importsToRemove: toBeRemoved, } = migrateRoute(childRoute, route, typeChecker, reflector, tracker); | ||
migratedRoutes.push(...migrated); | ||
@@ -301,3 +305,3 @@ skippedRoutes.push(...toBeSkipped); | ||
// if component is not a standalone component, skip it | ||
if (!isStandaloneComponent(componentDeclaration)) { | ||
if (!isStandaloneComponent(componentDeclaration, reflector)) { | ||
skippedRoutes.push({ path: routePath, file: route.routeFilePath }); | ||
@@ -304,0 +308,0 @@ return routeMigrationResults; |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -13,9 +13,9 @@ * License: MIT | ||
var project_tsconfig_paths = require('./project_tsconfig_paths-e9ccccbf.js'); | ||
var combine_units = require('./combine_units-2adebceb.js'); | ||
var combine_units = require('./combine_units-c36a3065.js'); | ||
require('os'); | ||
var ts = require('typescript'); | ||
var checker = require('./checker-e3da3b0a.js'); | ||
var program = require('./program-f984ab63.js'); | ||
var checker = require('./checker-3cbc9cc1.js'); | ||
var program = require('./program-561595c4.js'); | ||
require('path'); | ||
var migrate_ts_type_references = require('./migrate_ts_type_references-ed2c0669.js'); | ||
var migrate_ts_type_references = require('./migrate_ts_type_references-bb0c286a.js'); | ||
var assert = require('assert'); | ||
@@ -22,0 +22,0 @@ require('@angular-devkit/core'); |
'use strict'; | ||
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -17,7 +17,7 @@ * License: MIT | ||
require('@angular-devkit/core'); | ||
require('./combine_units-2adebceb.js'); | ||
require('./combine_units-c36a3065.js'); | ||
require('node:path/posix'); | ||
require('os'); | ||
require('typescript'); | ||
require('./checker-e3da3b0a.js'); | ||
require('./checker-3cbc9cc1.js'); | ||
require('fs'); | ||
@@ -27,4 +27,4 @@ require('module'); | ||
require('url'); | ||
require('./program-f984ab63.js'); | ||
require('./migrate_ts_type_references-ed2c0669.js'); | ||
require('./program-561595c4.js'); | ||
require('./migrate_ts_type_references-bb0c286a.js'); | ||
require('assert'); | ||
@@ -31,0 +31,0 @@ require('./leading_space-d190b83b.js'); |
/** | ||
* @license Angular v19.0.0 | ||
* @license Angular v19.0.1 | ||
* (c) 2010-2024 Google LLC. https://angular.io/ | ||
@@ -4,0 +4,0 @@ * License: MIT |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9893479
146171