@bikky/compiler 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/ASTHelper.d.ts +74 -0
  2. package/ASTHelper.d.ts.map +1 -0
  3. package/BiscuitCompiler.njsproj +89 -0
  4. package/BiscuitCompiler.njsproj.user +7 -0
  5. package/Libraries/BiscuitLibraries.d.ts +3 -0
  6. package/Libraries/BiscuitLibraries.d.ts.map +1 -0
  7. package/Libraries/BiscuitLibraries.js +3 -0
  8. package/Libraries/BiscuitLibraries.js.map +1 -0
  9. package/Libraries/BiscuitLibraries.ts +2 -0
  10. package/Libraries/GlobalTypes.d.ts +57 -0
  11. package/Libraries/MixinCode.d.ts +14 -0
  12. package/Libraries/MixinCode.d.ts.map +1 -0
  13. package/Libraries/MixinCode.js +109 -0
  14. package/Libraries/MixinCode.js.map +1 -0
  15. package/Libraries/MixinCode.ts +125 -0
  16. package/Libraries/package-lock.json +5 -0
  17. package/Source/ASTHelper.js +344 -0
  18. package/Source/ASTHelper.js.map +1 -0
  19. package/Source/ASTHelper.ts +373 -0
  20. package/Source/TSPatchTypes.d.ts +17 -0
  21. package/Transformers/CompilerInsertions.ts +21 -0
  22. package/Transformers/MacroTransformer.js +273 -0
  23. package/Transformers/MacroTransformer.js.map +1 -0
  24. package/Transformers/MacroTransformer.ts +304 -0
  25. package/Transformers/Macros.d.ts +3 -0
  26. package/Transformers/Macros.d.ts.map +1 -0
  27. package/Transformers/MixinTransformer.js +124 -0
  28. package/Transformers/MixinTransformer.js.map +1 -0
  29. package/Transformers/MixinTransformer.ts +151 -0
  30. package/Transformers/SuperTransform.d.ts +3 -0
  31. package/Transformers/SuperTransform.d.ts.map +1 -0
  32. package/Transformers/SuperTransform.js +117 -0
  33. package/Transformers/SuperTransform.js.map +1 -0
  34. package/Transformers/SuperTransform.ts +129 -0
  35. package/bin/Microsoft.NodejsTools.WebRole.dll +0 -0
  36. package/obj/Debug/BiscuitCompiler.njsproj.AssemblyReference.cache +0 -0
  37. package/obj/Debug/BiscuitCompiler.njsproj.CoreCompileInputs.cache +1 -0
  38. package/obj/Debug/BiscuitCompiler.njsproj.FileListAbsolute.txt +3 -0
  39. package/package.json +23 -0
  40. package/tsconfig.build.json +20 -0
  41. package/tsconfig.json +26 -0
  42. package/tsconfig.tsbuildinfo +1 -0
package/ASTHelper.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ import * as ts from "typescript";
2
+ export declare function Identifier(context: ts.TransformationContext, name: string): ts.Identifier;
3
+ export declare function StringLiteral(context: ts.TransformationContext, name: string): ts.StringLiteral;
4
+ export declare function StaticModifier(context: ts.TransformationContext): ts.Modifier;
5
+ export interface fromable {
6
+ from: (param: any) => any;
7
+ }
8
+ export declare class NamedExpression {
9
+ name: ts.Identifier;
10
+ constructor(name: ts.Identifier);
11
+ getName(): ts.Identifier;
12
+ rename(name: ts.Identifier): this;
13
+ }
14
+ export declare class VariableDeclaration extends NamedExpression {
15
+ modifiers?: ts.Modifier[];
16
+ value?: ts.Expression;
17
+ setValue(value: ts.Expression): this;
18
+ addModifier(modifier: ts.Modifier): this;
19
+ make(context: ts.TransformationContext): ts.Node;
20
+ }
21
+ export declare module VariableDeclaration {
22
+ function from(variable: ts.VariableDeclaration): VariableDeclaration;
23
+ }
24
+ export declare class PropertyDeclaration extends VariableDeclaration {
25
+ constructor(name: ts.Identifier | ts.ComputedPropertyName);
26
+ make(context: ts.TransformationContext): ts.PropertyDeclaration;
27
+ }
28
+ export declare module PropertyDeclaration {
29
+ function from(variable: ts.PropertyDeclaration | ts.VariableDeclaration): PropertyDeclaration;
30
+ }
31
+ export declare class CallExpression extends NamedExpression {
32
+ arguments: ts.Expression[];
33
+ addArgument(...arg: ts.Expression[]): this;
34
+ make(context: ts.TransformationContext): ts.CallExpression;
35
+ }
36
+ export declare class AccessExpression {
37
+ start: ts.Expression | ts.Identifier;
38
+ chain: ts.AccessExpression;
39
+ context: ts.TransformationContext;
40
+ constructor(context: ts.TransformationContext);
41
+ this(): this;
42
+ access(node: ts.Expression | ts.Identifier | ts.ComputedPropertyName): this;
43
+ make(): ts.AccessExpression;
44
+ }
45
+ export declare class ClassDeclaration extends NamedExpression {
46
+ original?: ts.ClassDeclaration;
47
+ decorators: ts.Decorator[];
48
+ extends: ts.Expression | undefined;
49
+ members: (ts.ClassElement)[];
50
+ static from(oldClass: ts.ClassDeclaration): ClassDeclaration;
51
+ addMemberAtStart(member: ts.ClassElement): this;
52
+ addMember(member: ts.ClassElement): this;
53
+ hasDecorator(identifier: string | ts.Identifier): boolean;
54
+ removeDecorator(identifier: string | ts.Identifier): this;
55
+ hasExtends(): boolean;
56
+ getExtends(): ts.Expression | undefined;
57
+ setExtends(Extends: ts.Expression | undefined): this;
58
+ static eachContextualNode(Class: ts.ClassDeclaration, foo: ts.Visitor, context: ts.TransformationContext): ts.ClassDeclaration;
59
+ update(context: ts.TransformationContext): ts.ClassDeclaration | undefined;
60
+ }
61
+ export declare class SourceFile {
62
+ original?: ts.SourceFile;
63
+ statements: ts.Statement[];
64
+ static from(oldfile: ts.SourceFile): SourceFile;
65
+ replaceNode(oldNode: ts.Statement, newNode: ts.Statement): this;
66
+ insertUnderImports(node: ts.Statement): this;
67
+ update(context: ts.TransformationContext): ts.SourceFile;
68
+ }
69
+ export declare function logError(node: ts.Node, error: string): undefined;
70
+ export declare module Printer {
71
+ function printNode(node: ts.Node, sourceFile: ts.SourceFile): string;
72
+ function printNodeFirstLine(node: ts.Node, sourceFile: ts.SourceFile): string;
73
+ }
74
+ //# sourceMappingURL=ASTHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ASTHelper.d.ts","sourceRoot":"","sources":["ASTHelper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,wBAAgB,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB,EAAE,IAAI,EAAE,MAAM,iBAEzE;AAED,wBAAgB,aA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,OAAO,EAAE,EAAE,CAAC,qBAAqB;CA0CxC;AAED,qBAAa,UAAU;IACtB,QAAQ,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;IACzB,UAAU,EAAE,EAAE,CAAC,SAAS,EAAE,CAAM;IAEhC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU;IAOlC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC,SAAS;IASxD,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS;IAUrC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB;CASxC;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAahE;AAED,sBAAc,OAAO,CAAC;IAGrB,SAAgB,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,UAEjE;IAED,SAAgB,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,UAM1E;CACD"}
@@ -0,0 +1,89 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup>
4
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5
+ <SchemaVersion>2.0</SchemaVersion>
6
+ <ProjectGuid>{3e2ffef5-c505-494a-be1e-0949a90874f1}</ProjectGuid>
7
+ <ProjectHome>.</ProjectHome>
8
+ <ProjectView>ProjectFiles</ProjectView>
9
+ <StartupFile>tsc.ts</StartupFile>
10
+ <WorkingDirectory>.</WorkingDirectory>
11
+ <OutputPath>.</OutputPath>
12
+ <ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
13
+ <EnableTypeScript>true</EnableTypeScript>
14
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">17.0</VisualStudioVersion>
15
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16
+ </PropertyGroup>
17
+ <PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
18
+ <PropertyGroup Condition="'$(Configuration)' == 'Release'" />
19
+ <ItemGroup>
20
+ <Content Include="package.json" />
21
+ <Content Include="Source\TSPatchTypes.d.ts" />
22
+ <Content Include="tsconfig.json" />
23
+ <Content Include="tsconfig.build.json" />
24
+ </ItemGroup>
25
+ <ItemGroup>
26
+ <TypeScriptCompile Include="Libraries\BiscuitLibraries.ts" />
27
+ <TypeScriptCompile Include="Source\ASTHelper.ts" />
28
+ <TypeScriptCompile Include="Transformers\MacroTransformer.ts">
29
+ <SubType>Code</SubType>
30
+ </TypeScriptCompile>
31
+ <TypeScriptCompile Include="Libraries\GlobalTypes.d.ts">
32
+ <SubType>Code</SubType>
33
+ </TypeScriptCompile>
34
+ <TypeScriptCompile Include="Libraries\MixinCode.ts" />
35
+ <TypeScriptCompile Include="Transformers\MixinTransformer.ts">
36
+ <SubType>Code</SubType>
37
+ </TypeScriptCompile>
38
+ <TypeScriptCompile Include="Transformers\SuperTransform.ts">
39
+ <SubType>Code</SubType>
40
+ </TypeScriptCompile>
41
+ </ItemGroup>
42
+ <ItemGroup>
43
+ <Folder Include="Libraries\" />
44
+ <Folder Include="Transformers\" />
45
+ </ItemGroup>
46
+ <ItemGroup>
47
+ <Script Include="Transformers\CompilerInsertions.ts" />
48
+ </ItemGroup>
49
+ <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
50
+ <Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsToolsV2.targets" />
51
+ <ProjectExtensions>
52
+ <VisualStudio>
53
+ <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
54
+ <WebProjectProperties>
55
+ <UseIIS>False</UseIIS>
56
+ <AutoAssignPort>True</AutoAssignPort>
57
+ <DevelopmentServerPort>0</DevelopmentServerPort>
58
+ <DevelopmentServerVPath>/</DevelopmentServerVPath>
59
+ <IISUrl>http://localhost:48022/</IISUrl>
60
+ <NTLMAuthentication>False</NTLMAuthentication>
61
+ <UseCustomServer>True</UseCustomServer>
62
+ <CustomServerUrl>http://localhost:1337</CustomServerUrl>
63
+ <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
64
+ </WebProjectProperties>
65
+ </FlavorProperties>
66
+ <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}" User="">
67
+ <WebProjectProperties>
68
+ <StartPageUrl>
69
+ </StartPageUrl>
70
+ <StartAction>CurrentPage</StartAction>
71
+ <AspNetDebugging>True</AspNetDebugging>
72
+ <SilverlightDebugging>False</SilverlightDebugging>
73
+ <NativeDebugging>False</NativeDebugging>
74
+ <SQLDebugging>False</SQLDebugging>
75
+ <ExternalProgram>
76
+ </ExternalProgram>
77
+ <StartExternalURL>
78
+ </StartExternalURL>
79
+ <StartCmdLineArguments>
80
+ </StartCmdLineArguments>
81
+ <StartWorkingDirectory>
82
+ </StartWorkingDirectory>
83
+ <EnableENC>False</EnableENC>
84
+ <AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
85
+ </WebProjectProperties>
86
+ </FlavorProperties>
87
+ </VisualStudio>
88
+ </ProjectExtensions>
89
+ </Project>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup>
4
+ <ToolsVersionPromptShown>4.2</ToolsVersionPromptShown>
5
+ <LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
6
+ </PropertyGroup>
7
+ </Project>
@@ -0,0 +1,3 @@
1
+ /// <reference path="GlobalTypes.d.ts" />
2
+ import "./MixinCode.js";
3
+ //# sourceMappingURL=BiscuitLibraries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BiscuitLibraries.d.ts","sourceRoot":"","sources":["BiscuitLibraries.ts"],"names":[],"mappings":";AACA,OAAO,gBAAgB,CAAC"}
@@ -0,0 +1,3 @@
1
+ /// <reference path="./GlobalTypes.d.ts" />
2
+ import "./MixinCode.js";
3
+ //# sourceMappingURL=BiscuitLibraries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BiscuitLibraries.js","sourceRoot":"","sources":["BiscuitLibraries.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ /// <reference path="./GlobalTypes.d.ts" />
2
+ import "./MixinCode.js";
@@ -0,0 +1,57 @@
1
+
2
+ type Writable<T> = { -readonly [P in keyof T]: T[P] }
3
+
4
+ type GetConstraints<Extras> = Extras extends (Function & { prototype: infer Constraints })[] ? Constraints : never;
5
+ type UnionToIntersection<U> =
6
+ (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
7
+ type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
8
+
9
+ type Class<T> = (new (...args: any[]) => T);
10
+ type AbstractClass<T> = Function & { prototype: T };
11
+ type ClassObject<T> = T extends (new (...args: any[]) => infer C) ? C : never;
12
+ type AbstractClassObject<T> = T extends (Function & { prototype: infer C }) ? C : never;
13
+ type AbstractClassArguments<T> = T extends abstract new (...args: infer A) => any ? A : never;
14
+ type ClassArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
15
+
16
+ type ConstructArguments<T> = T extends (new (...args: infer C) => any) ? C : never;
17
+ type Prototype<T> = (Function & { prototype: T });
18
+ type ObjectType<T> = T extends (new (...args: any[]) => infer C) ? C : never;
19
+
20
+ //Unfortunately Typescript doesn't currently support the following typing (as in the decorator's typing
21
+ // information will not properly alter typescript's typing information):
22
+ //First set of params are the ones supplied in the decorator, like: @mixin(common, extra1, extra2);
23
+ declare function mixin<
24
+ Super extends Object,
25
+ Extras extends Prototype<any>[]
26
+ >(common: Prototype<Super>, ...constraints: Extras): (
27
+ //Second set of params are the class the decorator is decorating, in this case the mixin.
28
+ <
29
+ MixinClass extends Function & { prototype: Object },
30
+ Mixin extends Prototype<MixinClass>,
31
+ ConstructorArgs extends ConstructArguments<Mixin>,
32
+ >
33
+ (mixin: MixinClass) => MixinClass & {
34
+ //We return a mix function that takes the class that the mixin
35
+ // is to be mixed onto. We want to ensure that the new class
36
+ // fulfills all the requirements listed with the decorator.
37
+ mix: <
38
+ Core extends AllConstraints<Super, GetConstraints<Extras>>
39
+ >
40
+ (core: Prototype<Core>) =>
41
+ //Lastly we return a function that requires the mixin's constructor arguments and returns
42
+ // an object which is a combination of the mixin and the provided core class.
43
+ (new (...args: ConstructorArgs) => Core & Mixin);
44
+ });
45
+
46
+ //This is the same code as the .mix property added by the decorator above. Since the decorator doesn't properly update
47
+ // typing information we'll need to continue calling makeMixer manually (for now). This should be removed once typescript's
48
+ // decorators are updated.
49
+ declare function makeMixer<
50
+ MixinClass extends (new (...args: any[]) => object),
51
+ Mixin extends ClassObject<MixinClass>,
52
+ ConstructorArgs extends ConstructArguments<MixinClass>,
53
+ Super extends Object, Extras extends Prototype<any>[]>
54
+ (mixin: MixinClass, common: Prototype<Super>, ...constraints: Extras): (
55
+ <Core extends AllConstraints<Super, GetConstraints<Extras>>>(core: { new(...args: any[]): Core } ) =>
56
+ (new (...args: ConstructorArgs) => Core & Mixin));
57
+
@@ -0,0 +1,14 @@
1
+ type GetConstraints<Extras> = Extras extends (Function & {
2
+ prototype: infer Constraints;
3
+ })[] ? Constraints : never;
4
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
5
+ type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
6
+ type Class<T> = (Function & {
7
+ prototype: T;
8
+ });
9
+ export declare function makeMixerFoo<Mixin extends Object, Super extends Object, Extras extends Class<any>[]>(mixin: Class<Mixin>, common: Class<Super>, ...constraints: Extras): <Core extends AllConstraints<Super, GetConstraints<Extras>>>(core: Function & {
10
+ prototype: Core;
11
+ }) => new (id: string, name: string, data: any, instance?: any) => Core & Mixin;
12
+ export declare function MixableClass<Base extends Class<Object>>(param: Base): Base;
13
+ export {};
14
+ //# sourceMappingURL=MixinCode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MixinCode.d.ts","sourceRoot":"","sources":["MixinCode.ts"],"names":[],"mappings":"AAiBA,KAAK,cAAc,CAAC,MAAM,IAAI,MAAM,SAAS,CAAC,QAAQ,GAAG;IAAE,SAAS,EAAE,MAAM,WAAW,CAAA;CAAE,CAAC,EAAE,GAAG,WAAW,GAAG,KAAK,CAAC;AACnH,KAAK,mBAAmB,CAAC,CAAC,IACzB,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AACpF,KAAK,cAAc,CAAC,KAAK,EAAE,WAAW,IAAI,mBAAmB,CAAC,WAAW,CAAC,SAAS,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;AAE5I,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG;IAAE,SAAS,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAM9C,wBAAgB,YAAY,CAAC,KAAK,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,EAAE,MAAM,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,EAClG,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,WAAW,EAAE,MAAM;;eA+DhD,MAAM,QAAQ,MAAM,QAAQ,GAAG,aAAa,GAAG,kBAEjE;AAED,wBAAgB,YAAY,CAAC,IAAI,SAAS,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,QAanE"}
@@ -0,0 +1,109 @@
1
+ //Propertydescriptor is needed to preserve getters and setters, otherwise we trigger them.
2
+ // We assign functions directly though to preserve the prototype chain when using super() [it's not working].
3
+ function duplicatePrototype(prototype, parent) {
4
+ var names = Array.from(Object.getOwnPropertyNames(prototype));
5
+ names.push(...Object.getOwnPropertySymbols(prototype));
6
+ var result = { __proto__: parent };
7
+ for (let i = names.length - 1; i >= 0; i--) {
8
+ let name = names[i];
9
+ var descriptor = Object.getOwnPropertyDescriptor(prototype, name);
10
+ Object.defineProperty(result, name, descriptor);
11
+ }
12
+ return result;
13
+ }
14
+ var mixingObject = [];
15
+ var mixingBases = [];
16
+ var mixingBaseProtos = [];
17
+ //The following parameter type allows abstract classes, where as new () => Core doesn't.
18
+ export function makeMixerFoo(mixin, common, ...constraints) {
19
+ if (typeof mixin !== "function" || !mixin.prototype)
20
+ throw new Error("Can only mix classes into other classes.");
21
+ return function mix(core) {
22
+ var newClass = eval(`
23
+ function Mixin_${mixin.name}(...args) {
24
+ //This allows us to change the prototype which the constructor uses for creating
25
+ // the object, forcing it to use the prototype of the child class rather than
26
+ // the prototype of the core.
27
+ var object = Reflect.construct(core, args, this.__proto__.constructor);
28
+ mixingObject.push(object);
29
+
30
+ //Mixins extend from Mixbase, which assigns the this object to the object created
31
+ // by core (above).
32
+ new (mixin)(...args);
33
+ mixingObject.shift();
34
+
35
+ return object;
36
+ };
37
+ Mixin_${mixin.name}
38
+ `);
39
+ var originalPrototypes = [];
40
+ var current = mixin;
41
+ originalPrototypes.push(current.prototype);
42
+ current = current.prototype;
43
+ while (mixingBaseProtos.indexOf(current.__proto__) < 0 && current.__proto__ != Object.prototype) {
44
+ originalPrototypes.push(current.__proto__);
45
+ current = current.__proto__;
46
+ }
47
+ var newPrototypes = [];
48
+ while (originalPrototypes.length > 0) {
49
+ current = originalPrototypes.pop();
50
+ let originalClass = current;
51
+ var prototype = newPrototypes.length == 0 ? core.prototype : newPrototypes[0];
52
+ let newmix = duplicatePrototype(current, prototype);
53
+ var edits = {
54
+ //We override the original isA so that this class appears to be a movable as well as other types.
55
+ isA(other) {
56
+ if (other.prototype == originalClass) {
57
+ return true;
58
+ }
59
+ else {
60
+ return super.isA(other);
61
+ }
62
+ },
63
+ };
64
+ Object.assign(newmix, edits);
65
+ newmix.__proto__ = prototype;
66
+ //This ensures any super calls in the edits to the prototype resolve correctly, because
67
+ // they're based on the original object the function is defined in, not the prototype the
68
+ // function ends up on.
69
+ edits.__proto__ = prototype;
70
+ newPrototypes.unshift(newmix);
71
+ }
72
+ newClass.prototype = newPrototypes[0];
73
+ newClass.prototype.constructor = newClass;
74
+ //I wanted to do this on object creation rather than having it be inherited, but that caused a problem with the value
75
+ // not being accessible in the constructor, which is necessary because the constructor can call other functons.
76
+ if (mixin.Super) {
77
+ //console.log("Configuring", mixin.name, "to have a parent that is", newClass.prototype.__proto__.constructor.name);
78
+ newClass.prototype[mixin.Super] = core.prototype;
79
+ }
80
+ //newClass.__proto__ = newPrototypes[0];
81
+ return newClass;
82
+ };
83
+ }
84
+ export function MixableClass(param) {
85
+ //This is done to preserve super calls in mixins.
86
+ class Mixbase extends param {
87
+ //@ts-ignore we don't need to call super in this child class.
88
+ constructor(...args) {
89
+ //We can't override the class' object using .call or .apply, but we can override it in the base class.
90
+ var object = mixingObject[0];
91
+ return object;
92
+ }
93
+ }
94
+ ;
95
+ mixingBases.push(Mixbase);
96
+ mixingBaseProtos.push(Mixbase.prototype);
97
+ return Mixbase;
98
+ }
99
+ if (typeof global !== "undefined") {
100
+ global.Mixable = MixableClass;
101
+ global.makeMixer = makeMixerFoo;
102
+ }
103
+ else {
104
+ Mixable = MixableClass;
105
+ makeMixer = makeMixerFoo;
106
+ window.Mixable = MixableClass;
107
+ window.makeMixer = makeMixerFoo;
108
+ }
109
+ //# sourceMappingURL=MixinCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MixinCode.js","sourceRoot":"","sources":["MixinCode.ts"],"names":[],"mappings":"AAEA,0FAA0F;AAC1F,6GAA6G;AAC7G,SAAS,kBAAkB,CAAC,SAAc,EAAE,MAAW;IACtD,IAAI,KAAK,GAAyB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAE,CAAC;IACrF,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;IACvD,IAAI,MAAM,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IACnC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3C,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,IAAI,CAAE,CAAC;QACnE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;KAChD;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,IAAI,YAAY,GAAU,EAAE,CAAC;AAQ7B,IAAI,WAAW,GAAoB,EAAE,CAAC;AACtC,IAAI,gBAAgB,GAAU,EAAE,CAAC;AAEjC,wFAAwF;AACxF,MAAM,UAAU,YAAY,CAC1B,KAAmB,EAAE,MAAoB,EAAE,GAAG,WAAmB;IAClE,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,CAAE,KAAa,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,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CAAC;IAC/B,MAAO,CAAC,SAAS,GAAG,YAAY,CAAC;CACvC"}
@@ -0,0 +1,125 @@
1
+ 
2
+
3
+ //Propertydescriptor is needed to preserve getters and setters, otherwise we trigger them.
4
+ // We assign functions directly though to preserve the prototype chain when using super() [it's not working].
5
+ function duplicatePrototype(prototype: any, parent: any) {
6
+ var names = (<(string | symbol)[]>Array.from(Object.getOwnPropertyNames(prototype)));
7
+ names.push(...Object.getOwnPropertySymbols(prototype));
8
+ var result = { __proto__: parent };
9
+ for (let i = names.length - 1; i >= 0; i--) {
10
+ let name = names[i];
11
+ var descriptor = Object.getOwnPropertyDescriptor(prototype, name)!;
12
+ Object.defineProperty(result, name, descriptor);
13
+ }
14
+ return result;
15
+ }
16
+
17
+ var mixingObject: any[] = [];
18
+ type GetConstraints<Extras> = Extras extends (Function & { prototype: infer Constraints })[] ? Constraints : never;
19
+ type UnionToIntersection<U> =
20
+ (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
21
+ type AllConstraints<Super, Constraints> = UnionToIntersection<Constraints> extends never ? Super : Super & UnionToIntersection<Constraints>;
22
+
23
+ type Class<T> = (Function & { prototype: T });
24
+
25
+ var mixingBases = <Class<Object>[]>[];
26
+ var mixingBaseProtos = <any[]>[];
27
+
28
+ //The following parameter type allows abstract classes, where as new () => Core doesn't.
29
+ export function makeMixerFoo<Mixin extends Object, Super extends Object, Extras extends Class<any>[]>
30
+ (mixin: Class<Mixin>, common: Class<Super>, ...constraints: Extras) {
31
+ if (typeof mixin !== "function" || !(mixin as any).prototype) throw new Error("Can only mix classes into other classes.");
32
+ return function mix<Core extends AllConstraints<Super, GetConstraints<Extras>>>(core: Function & { prototype: Core }) {
33
+ var newClass: Function = eval(`
34
+ function Mixin_${(mixin as any).name}(...args) {
35
+ //This allows us to change the prototype which the constructor uses for creating
36
+ // the object, forcing it to use the prototype of the child class rather than
37
+ // the prototype of the core.
38
+ var object = Reflect.construct(core, args, this.__proto__.constructor);
39
+ mixingObject.push(object);
40
+
41
+ //Mixins extend from Mixbase, which assigns the this object to the object created
42
+ // by core (above).
43
+ new (mixin)(...args);
44
+ mixingObject.shift();
45
+
46
+ return object;
47
+ };
48
+ Mixin_${(mixin as any).name}
49
+ `);
50
+ var originalPrototypes: any[] = [];
51
+ var current: any = mixin;
52
+ originalPrototypes.push(current.prototype);
53
+ current = current.prototype;
54
+ while (mixingBaseProtos.indexOf(current.__proto__) < 0 && current.__proto__ != Object.prototype) {
55
+ originalPrototypes.push(current.__proto__);
56
+ current = current.__proto__;
57
+ }
58
+ var newPrototypes: any[] = [];
59
+ while (originalPrototypes.length > 0) {
60
+ current = originalPrototypes.pop();
61
+ let originalClass = current;
62
+ var prototype = newPrototypes.length == 0 ? core.prototype : newPrototypes[0];
63
+ let newmix = duplicatePrototype(current, prototype);
64
+ var edits: any = {
65
+ //We override the original isA so that this class appears to be a movable as well as other types.
66
+ isA<T extends Object>(other: new (...args: any[]) => T) {
67
+ if ((<any>other).prototype == originalClass) {
68
+ return true;
69
+ }
70
+ else {
71
+ return super.isA(other);
72
+ }
73
+ },
74
+ }
75
+ Object.assign(newmix, edits);
76
+ newmix.__proto__ = prototype;
77
+ //This ensures any super calls in the edits to the prototype resolve correctly, because
78
+ // they're based on the original object the function is defined in, not the prototype the
79
+ // function ends up on.
80
+ edits.__proto__ = prototype;
81
+ newPrototypes.unshift(newmix);
82
+ }
83
+ newClass.prototype = newPrototypes[0];
84
+ newClass.prototype.constructor = newClass;
85
+ //I wanted to do this on object creation rather than having it be inherited, but that caused a problem with the value
86
+ // not being accessible in the constructor, which is necessary because the constructor can call other functons.
87
+ if ((<any>mixin).Super) {
88
+ //console.log("Configuring", mixin.name, "to have a parent that is", newClass.prototype.__proto__.constructor.name);
89
+ newClass.prototype[(<any>mixin).Super] = core.prototype;
90
+ }
91
+ //newClass.__proto__ = newPrototypes[0];
92
+
93
+ return <new (id: string, name: string, data: any, instance?: any) => Core & Mixin><any>newClass;
94
+ }
95
+ }
96
+
97
+ export function MixableClass<Base extends Class<Object>>(param: Base) {
98
+ //This is done to preserve super calls in mixins.
99
+ class Mixbase extends (<any>param) {
100
+ //@ts-ignore we don't need to call super in this child class.
101
+ constructor(...args: any[]) {
102
+ //We can't override the class' object using .call or .apply, but we can override it in the base class.
103
+ var object = mixingObject[0];
104
+ return object;
105
+ }
106
+ };
107
+ mixingBases.push(Mixbase);
108
+ mixingBaseProtos.push(Mixbase.prototype);
109
+ return <Base><any>Mixbase;
110
+ }
111
+
112
+ declare var window: any;
113
+ declare var Mixable: typeof MixableClass;
114
+ declare var makeMixer: typeof makeMixerFoo;
115
+
116
+ if (typeof global !== "undefined") {
117
+ (<any>global).Mixable = MixableClass;
118
+ (<any>global).makeMixer = makeMixerFoo;
119
+ }
120
+ else {
121
+ Mixable = MixableClass;
122
+ makeMixer = makeMixerFoo;
123
+ (<any>window).Mixable = MixableClass;
124
+ (<any>window).makeMixer = makeMixerFoo;
125
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "biscuit-typescript",
3
+ "version": "0.0.0",
4
+ "lockfileVersion": 1
5
+ }