forked from gajus/flow-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/flow-runtime/src/__tests__/__fixtures__/bugs/237-generic-arrays-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* @flow */ | ||
|
||
import type TypeContext from '../../../TypeContext'; | ||
|
||
function defineClass(t: TypeContext) { | ||
let _t$TypeParametersSymb; | ||
var _dec, _class, _class2, _temp; | ||
const _TestClassTypeParametersSymbol = Symbol("TestClassTypeParameters"); | ||
|
||
let TestClass = (_dec = t.annotate(t.class("TestClass", TestClass => { | ||
const ValueType = TestClass.typeParameter("ValueType"); | ||
return [t.method("testMethod")]; | ||
})), _dec(_class = (_temp = (_t$TypeParametersSymb = t.TypeParametersSymbol, _class2 = class TestClass { | ||
constructor() { | ||
this[_TestClassTypeParametersSymbol] = { | ||
ValueType: t.typeParameter("ValueType") | ||
}; | ||
} | ||
|
||
testMethod() { | ||
const items = t.array(this[_TestClassTypeParametersSymbol].ValueType) | ||
.assert(JSON.parse('[{ "a": null, "b": "b" }, { "a": "a", "b": null }]')); | ||
return items; | ||
} | ||
|
||
}), _class2[_t$TypeParametersSymb] = _TestClassTypeParametersSymbol, _temp)) || _class); | ||
return TestClass; | ||
} | ||
|
||
// will work for const test = TestClass<any>(); | ||
export function pass(t: TypeContext) { | ||
const TestClass = defineClass(t); | ||
const testClass = t.ref(TestClass, t.any()).assert(new TestClass()); | ||
return testClass.testMethod(); | ||
} | ||
|
||
// will fail for const test = TestClass(); | ||
export function fail(t: TypeContext) { | ||
const TestClass = defineClass(t); | ||
const testClass = t.ref(TestClass).assert(new TestClass()); | ||
return testClass.testMethod(); | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/flow-runtime/src/__tests__/__fixtures__/bugs/237-generic-arrays-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* @flow */ | ||
|
||
import type TypeContext from '../../../TypeContext'; | ||
|
||
function defineClass(t: TypeContext) { | ||
let _t$TypeParametersSymb; | ||
var _dec, _class, _class2, _temp; | ||
const _TestClassTypeParametersSymbol = Symbol("TestClassTypeParameters"); | ||
|
||
let TestClass = (_dec = t.annotate(t.class("TestClass", TestClass => { | ||
const Value1Type = TestClass.typeParameter("ValueType1"); | ||
const Value2Type = TestClass.typeParameter("ValueType2"); | ||
return [t.method("testMethod")]; | ||
})), _dec(_class = (_temp = (_t$TypeParametersSymb = t.TypeParametersSymbol, _class2 = class TestClass { | ||
constructor() { | ||
this[_TestClassTypeParametersSymbol] = { | ||
ValueType1: t.typeParameter("ValueType1"), | ||
ValueType2: t.typeParameter("ValueType2") | ||
}; | ||
} | ||
|
||
testMethod() { | ||
const items1 = t.array(this[_TestClassTypeParametersSymbol].ValueType1) | ||
.assert(JSON.parse('[{ "a": null, "b": "b" }, { "a": "a", "b": null }]')); | ||
const items2 = t.array(this[_TestClassTypeParametersSymbol].ValueType2) | ||
.assert(JSON.parse('[{ "a": null, "b": "b" }, { "a": "a", "b": null }]')); | ||
return items1.concat(items2); | ||
} | ||
|
||
}), _class2[_t$TypeParametersSymb] = _TestClassTypeParametersSymbol, _temp)) || _class); | ||
return TestClass; | ||
} | ||
|
||
// will work for const test = TestClass<any, any>(); | ||
export function pass(t: TypeContext) { | ||
const TestClass = defineClass(t); | ||
const testClass = t.ref(TestClass, t.any(), t.any()).assert(new TestClass()); | ||
return testClass.testMethod(); | ||
} | ||
|
||
// will fail for const test = TestClass(); | ||
export function fail(t: TypeContext) { | ||
const TestClass = defineClass(t); | ||
const testClass = t.ref(TestClass).assert(new TestClass()); | ||
return testClass.testMethod(); | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/flow-runtime/src/__tests__/__fixtures__/bugs/237-generic-arrays-3.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* @flow */ | ||
|
||
import type TypeContext from '../../../TypeContext'; | ||
|
||
function defineClass(t: TypeContext) { | ||
let _t$TypeParametersSymb; | ||
var _dec, _class, _class2, _temp; | ||
const _TestClassTypeParametersSymbol = Symbol("TestClassTypeParameters"); | ||
|
||
let TestClass = (_dec = t.annotate(t.class("TestClass", TestClass => { | ||
const ValueType = TestClass.typeParameter("ValueType"); | ||
return [t.method("testMethod")]; | ||
})), _dec(_class = (_temp = (_t$TypeParametersSymb = t.TypeParametersSymbol, _class2 = class TestClass { | ||
constructor() { | ||
this[_TestClassTypeParametersSymbol] = { | ||
ValueType: t.typeParameter("ValueType"), | ||
}; | ||
} | ||
|
||
testMethod( toParse ) { | ||
return t.array(this[_TestClassTypeParametersSymbol].ValueType).assert(JSON.parse(toParse)); | ||
} | ||
|
||
}), _class2[_t$TypeParametersSymb] = _TestClassTypeParametersSymbol, _temp)) || _class); | ||
return TestClass; | ||
} | ||
|
||
export function pass(t: TypeContext) { | ||
const TestClass = defineClass(t); | ||
|
||
t.ref(TestClass, t.string()).assert(new TestClass()).testMethod('["string1", "string2"]'); | ||
t.ref(TestClass, t.number()).assert(new TestClass()).testMethod('[0, 1, 2, 3]'); | ||
t.ref(TestClass, t.boolean()).assert(new TestClass()).testMethod('[false, true]'); | ||
return true; | ||
} | ||
|
||
// internal type still used for type validation inside testMethod() | ||
export function fail(t: TypeContext) { | ||
const TestClass = defineClass(t); | ||
t.ref(TestClass, t.number()).assert(new TestClass()) | ||
.testMethod('["string1", "string2"]'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters