Skip to content

Commit

Permalink
feat: refactor type model (#194)
Browse files Browse the repository at this point in the history
Removed the maps in the typemodel class and created a TypeNode object
  • Loading branch information
dstallenberg committed Dec 11, 2023
1 parent 6b4543a commit 4db8493
Show file tree
Hide file tree
Showing 11 changed files with 604 additions and 606 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class InferenceTypeModelFactory extends TypeModelFactory {
}

createNewTypeProbability(id: string, bindingId: string) {
this._typeModel.addId(bindingId);
this._typeModel.createTypeNode(bindingId);

if (id === bindingId) {
// don't set if the id and binding are equal
Expand Down
31 changes: 30 additions & 1 deletion libraries/analysis-javascript/lib/type/resolving/Type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

export interface ObjectType {
export class ObjectType {
// name -> id
properties: Map<string, string>;

Expand All @@ -31,6 +31,35 @@ export interface ObjectType {
parameterNames: Map<number, string>;
// id
return: Set<string>;

constructor() {
this.properties = new Map();
this.elements = new Set();
this.parameters = new Map();
this.parameterNames = new Map();
this.return = new Set();
}

public merge(other: ObjectType): ObjectType {
const combined = new ObjectType();

combined.properties = new Map([
...this.properties.entries(),
...other.properties.entries(),
]);
combined.elements = new Set(...this.elements, ...other.elements);
combined.parameters = new Map([
...this.parameters.entries(),
...other.parameters.entries(),
]);
combined.parameterNames = new Map([
...this.parameterNames.entries(),
...other.parameterNames.entries(),
]);
combined.return = new Set(...this.return, ...other.return);

return combined;
}
}

export const functionProperties = new Set([
Expand Down
Loading

0 comments on commit 4db8493

Please sign in to comment.