type
stringclasses 7
values | content
stringlengths 4
9.55k
| repo
stringlengths 7
96
| path
stringlengths 4
178
| language
stringclasses 1
value |
---|---|---|---|---|
MethodDeclaration |
openDialog(photo: PhotoData) {
const dialogConfig = new MatDialogConfig();
dialogConfig.autoFocus = true;
dialogConfig.data = {
id: photo.photoId,
url: photo.url
};
this.dialog.open(ImageDialogComponent, dialogConfig);
} | sublimeOne/projects | src/app/photos/photos.component.ts | TypeScript |
FunctionDeclaration |
export function fixtureFactory<T>(defaults: T): (params?: Partial<T>) => T {
return (params = {}) => merge({}, defaults, params)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it('should throw error on not JSON ABI', () => {
const inputJson = `abc`
expect(() => extractAbi(inputJson)).toThrow(MalformedAbiError, 'Not a json')
})
it('should throw error on malformed ABI', () => {
const inputJson = `{ "someProps": "abc" }`
expect(() => extractAbi(inputJson)).toThrow(MalformedAbiError, 'Not a valid ABI')
})
it('should work with simple abi', () => {
const inputJson = `[
{
"name": "piece",
"constant": false,
"payable": false,
"inputs": [],
"outputs": [],
"type": "function"
}
]
`
expect(extractAbi(inputJson)).toEqual([
{
name: 'piece',
constant: false,
payable: false,
inputs: [],
outputs: [],
type: 'function',
},
])
})
it('should work with nested abi (truffle style)', () => {
const inputJson = `{ "abi": [
{
"name": "piece",
"constant": false,
"payable": false,
"inputs": [],
"outputs": [],
"type": "function"
}
]
}`
expect(extractAbi(inputJson)).toEqual([
{
name: 'piece',
constant: false,
payable: false,
inputs: [],
outputs: [],
type: 'function',
},
])
})
it('should work with nested abi (@0x/solc-compiler style)', () => {
const inputJson = `{ "compilerOutput": { "abi": [
{
"name": "piece",
"constant": false,
"payable": false,
"inputs": [],
"outputs": [],
"type": "function"
}
]
} }`
expect(extractAbi(inputJson)).toEqual([
{
name: 'piece',
constant: false,
payable: false,
inputs: [],
outputs: [],
type: 'function',
},
])
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const inputJson = `abc`
expect(() => extractAbi(inputJson)).toThrow(MalformedAbiError, 'Not a json')
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => extractAbi(inputJson) | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const inputJson = `{ "someProps": "abc" }`
expect(() => extractAbi(inputJson)).toThrow(MalformedAbiError, 'Not a valid ABI')
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const inputJson = `[
{
"name": "piece",
"constant": false,
"payable": false,
"inputs": [],
"outputs": [],
"type": "function"
}
]
`
expect(extractAbi(inputJson)).toEqual([
{
name: 'piece',
constant: false,
payable: false,
inputs: [],
outputs: [],
type: 'function',
},
])
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const inputJson = `{ "abi": [
{
"name": "piece",
"constant": false,
"payable": false,
"inputs": [],
"outputs": [],
"type": "function"
}
]
}`
expect(extractAbi(inputJson)).toEqual([
{
name: 'piece',
constant: false,
payable: false,
inputs: [],
outputs: [],
type: 'function',
},
])
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const inputJson = `{ "compilerOutput": { "abi": [
{
"name": "piece",
"constant": false,
"payable": false,
"inputs": [],
"outputs": [],
"type": "function"
}
]
} }`
expect(extractAbi(inputJson)).toEqual([
{
name: 'piece',
constant: false,
payable: false,
inputs: [],
outputs: [],
type: 'function',
},
])
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const sampleBytecode = '1234abcd'
const resultBytecode = { bytecode: ensure0xPrefix(sampleBytecode) }
it('should return bytecode for bare bytecode string', () => {
expect(extractBytecode(sampleBytecode)).toEqual(resultBytecode)
})
it('should return bytecode for bare bytecode with 0x prefix', () => {
expect(extractBytecode(resultBytecode.bytecode)).toEqual(resultBytecode)
})
it('should return undefined for non-bytecode non-json input', () => {
expect(extractBytecode('surely-not-bytecode')).toEqual(undefined)
})
it('should return undefined for simple abi without bytecode', () => {
expect(extractBytecode(`[{ "name": "piece" }]`)).toEqual(undefined)
})
it('should return undefined for nested abi without bytecode', () => {
expect(extractBytecode(`{ "abi": [{ "name": "piece" }] }`)).toEqual(undefined)
})
it('should return bytecode from nested abi (truffle style)', () => {
expect(extractBytecode(`{ "bytecode": "${sampleBytecode}" }`)).toEqual(resultBytecode)
})
it('should return bytecode from nested abi (ethers style)', () => {
const inputJson = `{ "evm": { "bytecode": { "object": "${sampleBytecode}" }}}`
expect(extractBytecode(inputJson)).toEqual(resultBytecode)
})
it('should return bytecode from nested abi (@0x/sol-compiler style)', () => {
expect(
extractBytecode(`{ "compilerOutput": { "evm": { "bytecode": { "object": "${sampleBytecode}" } } } }`),
).toEqual(resultBytecode)
})
it('should return undefined when nested abi bytecode is malformed', () => {
expect(extractBytecode(`{ "bytecode": "surely-not-bytecode" }`)).toEqual(undefined)
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(sampleBytecode)).toEqual(resultBytecode)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(resultBytecode.bytecode)).toEqual(resultBytecode)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode('surely-not-bytecode')).toEqual(undefined)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(`[{ "name": "piece" }]`)).toEqual(undefined)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(`{ "abi": [{ "name": "piece" }] }`)).toEqual(undefined)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(`{ "bytecode": "${sampleBytecode}" }`)).toEqual(resultBytecode)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const inputJson = `{ "evm": { "bytecode": { "object": "${sampleBytecode}" }}}`
expect(extractBytecode(inputJson)).toEqual(resultBytecode)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(
extractBytecode(`{ "compilerOutput": { "evm": { "bytecode": { "object": "${sampleBytecode}" } } } }`),
).toEqual(resultBytecode)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(`{ "bytecode": "surely-not-bytecode" }`)).toEqual(undefined)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const devUserDoc = `{
"devdoc": {
"author" : "Larry A. Gardner",
"details" : "All function calls are currently implemented without side effects",
"methods" :
{
"age(uint256)" :
{
"author" : "Mary A. Botanist",
"details" : "The Alexandr N. Tetearing algorithm could increase precision",
"params" :
{
"rings" : "The number of rings from dendrochronological sample"
},
"return" : "age in years, rounded up for partial years"
}
},
"title" : "A simulator for trees"
},
"userdoc": {
"methods" :
{
"age(uint256)" :
{
"notice" : "Calculate tree age in years, rounded up, for live trees"
}
},
"notice" : "You can use this contract for only the most basic simulation"
}
}`
const userDoc = `{
"userdoc": {
"methods" :
{
"age(uint256)" :
{
"notice" : "Calculate tree age in years, rounded up, for live trees"
}
},
"notice" : "You can use this contract for only the most basic simulation"
}
}`
it('should merge devdoc and userdoc', () => {
const doc = extractDocumentation(devUserDoc)
expect(doc).toEqual({
author: 'Larry A. Gardner',
details: 'All function calls are currently implemented without side effects',
methods: {
'age(uint256)': {
author: 'Mary A. Botanist',
details: 'The Alexandr N. Tetearing algorithm could increase precision',
notice: 'Calculate tree age in years, rounded up, for live trees',
params: { rings: 'The number of rings from dendrochronological sample' },
return: 'age in years, rounded up for partial years',
},
},
notice: 'You can use this contract for only the most basic simulation',
title: 'A simulator for trees',
})
})
it('should parse userdoc only', () => {
const doc = extractDocumentation(userDoc)
expect(doc).toEqual({
methods: { 'age(uint256)': { notice: 'Calculate tree age in years, rounded up, for live trees' } },
notice: 'You can use this contract for only the most basic simulation',
})
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const doc = extractDocumentation(devUserDoc)
expect(doc).toEqual({
author: 'Larry A. Gardner',
details: 'All function calls are currently implemented without side effects',
methods: {
'age(uint256)': {
author: 'Mary A. Botanist',
details: 'The Alexandr N. Tetearing algorithm could increase precision',
notice: 'Calculate tree age in years, rounded up, for live trees',
params: { rings: 'The number of rings from dendrochronological sample' },
return: 'age in years, rounded up for partial years',
},
},
notice: 'You can use this contract for only the most basic simulation',
title: 'A simulator for trees',
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const doc = extractDocumentation(userDoc)
expect(doc).toEqual({
methods: { 'age(uint256)': { notice: 'Calculate tree age in years, rounded up, for live trees' } },
notice: 'You can use this contract for only the most basic simulation',
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const linkRef1: BytecodeLinkReference = { reference: '__./ContractWithLibrary.sol:TestLibrar__' }
const bytecodeStr1 = `565b005b60005481565b73${linkRef1.reference}63b7203ec673${linkRef1.reference}63b7203ec6846040518263ffffffff167c010000`
const linkRef2: BytecodeLinkReference = { reference: '__TestLibrary___________________________' }
const bytecodeObj2 = {
bytecode: `0x565b005b60005481565b73${linkRef2.reference}63b7203ec673${linkRef2.reference}63b7203ec6846040518263ffffffff167c010000`,
}
const linkRef3: BytecodeLinkReference = { reference: '__$17aeeb93c354b782f3950a7152e030370b$__' }
const bytecodeObj3 = {
evm: {
bytecode: {
object: `0x565b005b60005481565b73${linkRef3.reference}63b7203ec673${linkRef3.reference}63b7203ec6846040518263ffffffff167c010000`,
},
},
}
const linkRef4: BytecodeLinkReference = {
reference: linkRef3.reference,
name: 'ContractWithLibrary.sol:TestLibrary',
}
const bytecodeObj4 = {
evm: {
bytecode: {
linkReferences: {
'ContractWithLibrary.sol': {
TestLibrary: [
{ length: 20, start: 151 },
{ length: 20, start: 177 },
],
},
},
object: bytecodeObj3.evm.bytecode.object,
},
},
}
const bytecodeObj5 = {
compilerOutput: bytecodeObj4,
}
const bytecodeObj6 = {
bytecode: bytecodeObj3.evm.bytecode.object,
linkReferences: {
'ContractWithLibrary.sol': {
TestLibrary: [
{ length: 20, start: 151 },
{ length: 20, start: 177 },
],
},
},
}
it('should extract solc 0.4 link references', () => {
expect(extractBytecode(bytecodeStr1)).toEqual({
bytecode: `0x${bytecodeStr1}`,
linkReferences: [linkRef1],
})
})
it('should extract bare library contract name link references', () => {
expect(extractBytecode(JSON.stringify(bytecodeObj2))).toEqual({
bytecode: bytecodeObj2.bytecode,
linkReferences: [linkRef2],
})
})
it('should extract solc 0.5 link references', () => {
expect(extractBytecode(JSON.stringify(bytecodeObj3))).toEqual({
bytecode: bytecodeObj3.evm.bytecode.object,
linkReferences: [linkRef3],
})
})
it('should extract solc 0.5 link references with contract names', () => {
expect(extractBytecode(JSON.stringify(bytecodeObj4))).toEqual({
bytecode: bytecodeObj4.evm.bytecode.object,
linkReferences: [linkRef4],
})
})
it('should handle extracting link references in (@0x/sol-compiler) style', () => {
expect(extractBytecode(JSON.stringify(bytecodeObj5))).toEqual({
bytecode: bytecodeObj5.compilerOutput.evm.bytecode.object,
linkReferences: [linkRef4],
})
})
it('should still extract solc 0.5 link references when plain bytecode is also present', () => {
const bytecodeObj4a = {
...bytecodeObj4,
bytecode: bytecodeObj4.evm.bytecode.object,
}
expect(extractBytecode(JSON.stringify(bytecodeObj4a))).toEqual({
bytecode: bytecodeObj4.evm.bytecode.object,
linkReferences: [linkRef4],
})
})
it('should extract hardhat style link references', () => {
expect(extractBytecode(JSON.stringify(bytecodeObj6))).toEqual({
bytecode: bytecodeObj4.evm.bytecode.object,
linkReferences: [linkRef4],
})
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(bytecodeStr1)).toEqual({
bytecode: `0x${bytecodeStr1}`,
linkReferences: [linkRef1],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(JSON.stringify(bytecodeObj2))).toEqual({
bytecode: bytecodeObj2.bytecode,
linkReferences: [linkRef2],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(JSON.stringify(bytecodeObj3))).toEqual({
bytecode: bytecodeObj3.evm.bytecode.object,
linkReferences: [linkRef3],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(JSON.stringify(bytecodeObj4))).toEqual({
bytecode: bytecodeObj4.evm.bytecode.object,
linkReferences: [linkRef4],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(JSON.stringify(bytecodeObj5))).toEqual({
bytecode: bytecodeObj5.compilerOutput.evm.bytecode.object,
linkReferences: [linkRef4],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const bytecodeObj4a = {
...bytecodeObj4,
bytecode: bytecodeObj4.evm.bytecode.object,
}
expect(extractBytecode(JSON.stringify(bytecodeObj4a))).toEqual({
bytecode: bytecodeObj4.evm.bytecode.object,
linkReferences: [linkRef4],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(extractBytecode(JSON.stringify(bytecodeObj6))).toEqual({
bytecode: bytecodeObj4.evm.bytecode.object,
linkReferences: [linkRef4],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it("should prepend 0x when it's missing", () => {
expect(ensure0xPrefix('1234')).toEqual('0x1234')
})
it('should return string unchanged when it has 0x prefix', () => {
expect(ensure0xPrefix('0x1234')).toEqual('0x1234')
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(ensure0xPrefix('1234')).toEqual('0x1234')
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(ensure0xPrefix('0x1234')).toEqual('0x1234')
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it('works', () => {
const expectedEvent: RawEventAbiDefinition = {
anonymous: false,
inputs: [
{ indexed: true, name: '_from', type: 'address' },
{ indexed: false, name: '_value', type: 'uint256' },
],
name: 'Deposit',
type: 'event',
}
const parsedEvent = parseEvent(expectedEvent)
expect(parsedEvent).toEqual({
name: 'Deposit',
isAnonymous: false,
inputs: [
{ name: '_from', isIndexed: true, type: { type: 'address', originalType: 'address' } },
{ name: '_value', isIndexed: false, type: { type: 'uinteger', bits: 256, originalType: 'uint256' } },
],
})
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const expectedEvent: RawEventAbiDefinition = {
anonymous: false,
inputs: [
{ indexed: true, name: '_from', type: 'address' },
{ indexed: false, name: '_value', type: 'uint256' },
],
name: 'Deposit',
type: 'event',
}
const parsedEvent = parseEvent(expectedEvent)
expect(parsedEvent).toEqual({
name: 'Deposit',
isAnonymous: false,
inputs: [
{ name: '_from', isIndexed: true, type: { type: 'address', originalType: 'address' } },
{ name: '_value', isIndexed: false, type: { type: 'uinteger', bits: 256, originalType: 'uint256' } },
],
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
describe('functions', () => {
const abiPiece = {
constant: false,
inputs: [
{
name: 'foo',
type: 'uint256',
},
{
name: 'bar',
type: 'bytes32',
},
],
name: 'doFooBar',
outputs: [],
payable: false,
type: 'function',
}
const documentation = {
details: 'A cool contract that does cool stuff',
methods: {
'doFooBar(uint256,bytes32)': {
details: 'Does a bit of foo and some bar',
params: {
foo: 'A bit of foo',
bar: 'Some bar',
},
},
},
}
it('should get the documentation', () => {
const res = parse([abiPiece], 'ACoolContract', documentation)
expect(res.functions.doFooBar[0].documentation).toEqual(documentation.methods['doFooBar(uint256,bytes32)'])
expect(res.documentation!.details).toEqual(documentation.details)
})
})
describe('fallback functions', () => {
it('should work on output-less fallback functions', () => {
const fallbackAbiFunc: RawAbiDefinition = {
payable: true,
stateMutability: 'payable',
type: 'fallback',
} as any
expect(() => parse([fallbackAbiFunc], 'fallback')).not.toThrow()
})
})
describe('empty names should be parsed as undefined', () => {
it('should work on output-less fallback functions', () => {
const event: RawAbiDefinition = {
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'bytes32',
name: '',
type: 'bytes32',
},
],
name: 'log_bytes32',
type: 'event',
} as any
expect(parse([event], 'sc1')).toEqual({
constructor: [],
events: {
log_bytes32: [
{
inputs: [
{
isIndexed: false,
name: undefined,
type: {
size: 32,
type: 'bytes',
originalType: 'bytes32',
},
},
],
name: 'log_bytes32',
isAnonymous: false,
},
],
},
fallback: undefined,
documentation: undefined,
functions: {},
name: 'Sc1',
rawName: 'sc1',
})
})
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const abiPiece = {
constant: false,
inputs: [
{
name: 'foo',
type: 'uint256',
},
{
name: 'bar',
type: 'bytes32',
},
],
name: 'doFooBar',
outputs: [],
payable: false,
type: 'function',
}
const documentation = {
details: 'A cool contract that does cool stuff',
methods: {
'doFooBar(uint256,bytes32)': {
details: 'Does a bit of foo and some bar',
params: {
foo: 'A bit of foo',
bar: 'Some bar',
},
},
},
}
it('should get the documentation', () => {
const res = parse([abiPiece], 'ACoolContract', documentation)
expect(res.functions.doFooBar[0].documentation).toEqual(documentation.methods['doFooBar(uint256,bytes32)'])
expect(res.documentation!.details).toEqual(documentation.details)
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const res = parse([abiPiece], 'ACoolContract', documentation)
expect(res.functions.doFooBar[0].documentation).toEqual(documentation.methods['doFooBar(uint256,bytes32)'])
expect(res.documentation!.details).toEqual(documentation.details)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it('should work on output-less fallback functions', () => {
const fallbackAbiFunc: RawAbiDefinition = {
payable: true,
stateMutability: 'payable',
type: 'fallback',
} as any
expect(() => parse([fallbackAbiFunc], 'fallback')).not.toThrow()
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const fallbackAbiFunc: RawAbiDefinition = {
payable: true,
stateMutability: 'payable',
type: 'fallback',
} as any
expect(() => parse([fallbackAbiFunc], 'fallback')).not.toThrow()
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => parse([fallbackAbiFunc], 'fallback') | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it('should work on output-less fallback functions', () => {
const event: RawAbiDefinition = {
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'bytes32',
name: '',
type: 'bytes32',
},
],
name: 'log_bytes32',
type: 'event',
} as any
expect(parse([event], 'sc1')).toEqual({
constructor: [],
events: {
log_bytes32: [
{
inputs: [
{
isIndexed: false,
name: undefined,
type: {
size: 32,
type: 'bytes',
originalType: 'bytes32',
},
},
],
name: 'log_bytes32',
isAnonymous: false,
},
],
},
fallback: undefined,
documentation: undefined,
functions: {},
name: 'Sc1',
rawName: 'sc1',
})
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const event: RawAbiDefinition = {
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'bytes32',
name: '',
type: 'bytes32',
},
],
name: 'log_bytes32',
type: 'event',
} as any
expect(parse([event], 'sc1')).toEqual({
constructor: [],
events: {
log_bytes32: [
{
inputs: [
{
isIndexed: false,
name: undefined,
type: {
size: 32,
type: 'bytes',
originalType: 'bytes32',
},
},
],
name: 'log_bytes32',
isAnonymous: false,
},
],
},
fallback: undefined,
documentation: undefined,
functions: {},
name: 'Sc1',
rawName: 'sc1',
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
(params = {}) => merge({}, defaults, params) | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
const fnFactory = fixtureFactory<FunctionDeclaration>({
name: 'constant',
inputs: [],
outputs: [{ type: { type: 'string', originalType: 'string' }, name: 'output' }],
stateMutability: 'view',
})
const viewFn = fnFactory()
const pureFn = fnFactory({ stateMutability: 'pure' })
const payableFn = fnFactory(fnFactory({ stateMutability: 'payable' }))
const nonPayableFn = fnFactory(fnFactory({ stateMutability: 'nonpayable' }))
const viewWithInputs = fnFactory({
stateMutability: 'pure',
inputs: [{ type: { type: 'string', originalType: 'string' }, name: 'output' }],
})
describe('isConstant', () => {
it('works', () => {
expect(isConstant(viewFn)).toEqual(true)
expect(isConstant(pureFn)).toEqual(true)
expect(isConstant(payableFn)).toEqual(false)
expect(isConstant(nonPayableFn)).toEqual(false)
expect(isConstant(viewWithInputs)).toEqual(false)
})
})
describe('isConstantFn', () => {
it('works', () => {
expect(isConstantFn(viewFn)).toEqual(false)
expect(isConstantFn(pureFn)).toEqual(false)
expect(isConstantFn(payableFn)).toEqual(false)
expect(isConstantFn(nonPayableFn)).toEqual(false)
expect(isConstantFn(viewWithInputs)).toEqual(true)
})
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it('works', () => {
expect(isConstant(viewFn)).toEqual(true)
expect(isConstant(pureFn)).toEqual(true)
expect(isConstant(payableFn)).toEqual(false)
expect(isConstant(nonPayableFn)).toEqual(false)
expect(isConstant(viewWithInputs)).toEqual(false)
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(isConstant(viewFn)).toEqual(true)
expect(isConstant(pureFn)).toEqual(true)
expect(isConstant(payableFn)).toEqual(false)
expect(isConstant(nonPayableFn)).toEqual(false)
expect(isConstant(viewWithInputs)).toEqual(false)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it('works', () => {
expect(isConstantFn(viewFn)).toEqual(false)
expect(isConstantFn(pureFn)).toEqual(false)
expect(isConstantFn(payableFn)).toEqual(false)
expect(isConstantFn(nonPayableFn)).toEqual(false)
expect(isConstantFn(viewWithInputs)).toEqual(true)
})
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
expect(isConstantFn(viewFn)).toEqual(false)
expect(isConstantFn(pureFn)).toEqual(false)
expect(isConstantFn(payableFn)).toEqual(false)
expect(isConstantFn(nonPayableFn)).toEqual(false)
expect(isConstantFn(viewWithInputs)).toEqual(true)
} | ItsNickBarry/TypeChain | packages/typechain/test/parser/abiParser.test.ts | TypeScript |
ArrowFunction |
() => {
it('create an instance', () => {
const pipe = new MinmaxPipe();
expect(pipe).toBeTruthy();
});
} | taylordeckard/trading-sim | src/app/charts/minmax.pipe.spec.ts | TypeScript |
ArrowFunction |
() => {
const pipe = new MinmaxPipe();
expect(pipe).toBeTruthy();
} | taylordeckard/trading-sim | src/app/charts/minmax.pipe.spec.ts | TypeScript |
ArrowFunction |
() => this.server.register({
plugin: {
name: options.path,
register: async (server, registerOpts) => {
server.route({
method: 'GET',
path: options.path,
handler: async (request, h) => {
let result;
for (const handler of this.routes.get(options.path)!) {
result = await handler(request.raw.req.headers);
if (result) {
return result;
}
}
return h.continue;
}
});
}
}
}) | charlex/cloud-trace-nodejs | test/web-frameworks/hapi17.ts | TypeScript |
ArrowFunction |
async (server, registerOpts) => {
server.route({
method: 'GET',
path: options.path,
handler: async (request, h) => {
let result;
for (const handler of this.routes.get(options.path)!) {
result = await handler(request.raw.req.headers);
if (result) {
return result;
}
}
return h.continue;
}
});
} | charlex/cloud-trace-nodejs | test/web-frameworks/hapi17.ts | TypeScript |
ArrowFunction |
async (request, h) => {
let result;
for (const handler of this.routes.get(options.path)!) {
result = await handler(request.raw.req.headers);
if (result) {
return result;
}
}
return h.continue;
} | charlex/cloud-trace-nodejs | test/web-frameworks/hapi17.ts | TypeScript |
ClassDeclaration |
export class Hapi17 implements WebFramework {
static commonName = `hapi@17`;
static expectedTopStackFrame = '_executeWrap';
static versionRange = '>=7.5';
private server: hapi_17.Server;
// We can't add two routes on the same path.
// So instead of registering a new Hapi plugin per path,
// register only the first time -- passing a function that will iterate
// through a list of routes keyed under the path.
private routes = new Map<string, WebFrameworkHandlerFunction[]>();
private registering = Promise.resolve();
constructor() {
const hapi = require('../plugins/fixtures/hapi17') as typeof hapi_17;
this.server = new hapi.Server();
}
addHandler(options: WebFrameworkAddHandlerOptions): void {
let shouldRegister = false;
if (!this.routes.has(options.path)) {
this.routes.set(options.path, [options.fn]);
shouldRegister = true;
} else {
this.routes.get(options.path)!.push(options.fn);
}
// Only register a new plugin for the first occurrence of this path.
if (shouldRegister) {
this.registering = this.registering.then(() => this.server.register({
plugin: {
name: options.path,
register: async (server, registerOpts) => {
server.route({
method: 'GET',
path: options.path,
handler: async (request, h) => {
let result;
for (const handler of this.routes.get(options.path)!) {
result = await handler(request.raw.req.headers);
if (result) {
return result;
}
}
return h.continue;
}
});
}
}
}));
}
}
async listen(port: number): Promise<number> {
await this.registering;
this.server.settings.port = port;
await this.server.start();
return Number(this.server.info!.port);
}
shutdown(): void {
this.server.stop();
}
} | charlex/cloud-trace-nodejs | test/web-frameworks/hapi17.ts | TypeScript |
MethodDeclaration |
addHandler(options: WebFrameworkAddHandlerOptions): void {
let shouldRegister = false;
if (!this.routes.has(options.path)) {
this.routes.set(options.path, [options.fn]);
shouldRegister = true;
} else {
this.routes.get(options.path)!.push(options.fn);
}
// Only register a new plugin for the first occurrence of this path.
if (shouldRegister) {
this.registering = this.registering.then(() => this.server.register({
plugin: {
name: options.path,
register: async (server, registerOpts) => {
server.route({
method: 'GET',
path: options.path,
handler: async (request, h) => {
let result;
for (const handler of this.routes.get(options.path)!) {
result = await handler(request.raw.req.headers);
if (result) {
return result;
}
}
return h.continue;
}
});
}
}
}));
}
} | charlex/cloud-trace-nodejs | test/web-frameworks/hapi17.ts | TypeScript |
MethodDeclaration |
async listen(port: number): Promise<number> {
await this.registering;
this.server.settings.port = port;
await this.server.start();
return Number(this.server.info!.port);
} | charlex/cloud-trace-nodejs | test/web-frameworks/hapi17.ts | TypeScript |
MethodDeclaration |
shutdown(): void {
this.server.stop();
} | charlex/cloud-trace-nodejs | test/web-frameworks/hapi17.ts | TypeScript |
ArrowFunction |
e => undefined | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.onSettingsChanged() | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
e => {
if (e.affectsConfiguration('python.dataScience', undefined)) {
// When config changes happen, recreate our commands.
this.dispose();
}
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.isCommandSupported(NotebookCommand, cancelToken) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.getUsableJupyterPythonImpl(cancelToken) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (cancelToken?: CancellationToken): Promise<boolean> => {
// See if we can find the command nbconvert
return Cancellation.race(() => this.isCommandSupported(ConvertCommand), cancelToken);
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.isCommandSupported(ConvertCommand) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (cancelToken?: CancellationToken): Promise<boolean> => {
// See if we can find the command ipykernel
return Cancellation.race(() => this.isCommandSupported(KernelCreateCommand), cancelToken);
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.isCommandSupported(KernelCreateCommand) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (cancelToken?: CancellationToken): Promise<boolean> => {
// See if we can find the command kernelspec
return Cancellation.race(() => this.isCommandSupported(KernelSpecCommand), cancelToken);
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.isCommandSupported(KernelSpecCommand) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async () => {
let connection: IConnection;
let kernelSpec: IJupyterKernelSpec | undefined;
// If our uri is undefined or if it's set to local launch we need to launch a server locally
if (!uri) {
const launchResults = await this.startNotebookServer(useDefaultConfig, cancelToken);
if (launchResults) {
connection = launchResults.connection;
kernelSpec = launchResults.kernelSpec;
} else {
// Throw a cancellation error if we were canceled.
Cancellation.throwIfCanceled(cancelToken);
// Otherwise we can't connect
throw new Error(localize.DataScience.jupyterNotebookFailure().format(''));
}
} else {
// If we have a URI spec up a connection info for it
connection = this.createRemoteConnectionInfo(uri);
kernelSpec = undefined;
}
try {
// If we don't have a kernel spec yet, check using our current connection
if (!kernelSpec) {
kernelSpec = await this.getMatchingKernelSpec(connection, cancelToken);
}
// If still not found, log an error (this seems possible for some people, so use the default)
if (!kernelSpec) {
this.logger.logError(localize.DataScience.jupyterKernelSpecNotFound());
}
// Try to connect to our jupyter process
const result = this.serviceContainer.get<INotebookServer>(INotebookServer);
await result.connect(connection, kernelSpec, cancelToken, workingDir);
return result;
} catch (err) {
// Something else went wrong
throw new Error(localize.DataScience.jupyterNotebookConnectFailed().format(connection.baseUrl));
}
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (file: string): Promise<void> => {
// First we find a way to start a notebook server
const notebookCommand = await this.findBestCommand('notebook');
if (!notebookCommand) {
throw new Error(localize.DataScience.jupyterNotSupported());
}
const args: string[] = [`--NotebookApp.file_to_run=${file}`];
// Don't wait for the exec to finish and don't dispose. It's up to the user to kill the process
notebookCommand.exec(args, { throwOnStdErr: false, encoding: 'utf8' }).ignoreErrors();
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (file: string, template: string): Promise<string> => {
// First we find a way to start a nbconvert
const convert = await this.findBestCommand(ConvertCommand);
if (!convert) {
throw new Error(localize.DataScience.jupyterNbConvertNotSupported());
}
// Wait for the nbconvert to finish
const result = await convert.exec([file, '--to', 'python', '--stdout', '--template', template], { throwOnStdErr: false, encoding: 'utf8' });
if (result.stderr) {
// Stderr on nbconvert doesn't indicate failure. Just log the result
this.logger.logInformation(result.stderr);
}
return result.stdout;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.sessionManager.getActiveKernelSpecs(connection) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => this.enumerateSpecs(cancelToken) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
(uri: string): IConnection => {
let url: URL;
try {
url = new URL(uri);
} catch (err) {
// This should already have been parsed when set, so just throw if it's not right here
throw err;
}
return {
baseUrl: `${url.protocol}//${url.host}${url.pathname}`,
token: `${url.searchParams.get('token')}`,
localLaunch: false,
dispose: noop
};
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
() => {
launchResult.dispose();
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (cancelToken?: CancellationToken): Promise<PythonInterpreter | undefined> => {
// This should be the best interpreter for notebooks
const found = await this.findBestCommand(NotebookCommand, cancelToken);
if (found) {
return found.interpreter();
}
return undefined;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (cancelToken?: CancellationToken): Promise<JupyterServerInfo[] | undefined> => {
// We have a small python file here that we will execute to get the server info from all running Jupyter instances
const bestInterpreter = await this.getUsableJupyterPython(cancelToken);
if (bestInterpreter) {
const newOptions: SpawnOptions = { mergeStdOutErr: true, token: cancelToken };
newOptions.env = await this.fixupCondaEnv(newOptions.env, bestInterpreter);
const processService = await this.processServiceFactory.create();
const file = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'datascience', 'getServerInfo.py');
const serverInfoString = await processService.exec(bestInterpreter.path, [file], newOptions);
let serverInfos: JupyterServerInfo[];
try {
// Parse out our results, return undefined if we can't suss it out
serverInfos = JSON.parse(serverInfoString.stdout.trim()) as JupyterServerInfo[];
} catch (err) {
return undefined;
}
return serverInfos;
}
return undefined;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async () => {
if (!diskPath) {
return;
}
try {
await fs.remove(path.dirname(diskPath));
} catch {
noop();
}
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (specName: string, cancelToken?: CancellationToken): Promise<string | undefined> => {
// Enumerate all specs and get path for the match
const specs = await this.enumerateSpecs(cancelToken);
const match = specs.find(s => {
const js = s as JupyterKernelSpec;
return js && js.name === specName;
}) as JupyterKernelSpec;
return match ? match.specFile : undefined;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
s => {
const js = s as JupyterKernelSpec;
return js && js.name === specName;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async () => {
// Try ten times. Process may still be up and running.
// We don't want to do async as async dispose means it may never finish and then we don't
// delete
let count = 0;
while (count < 10) {
try {
await fs.remove(resultDir);
count = 10;
} catch {
count += 1;
}
}
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (command: string, cancelToken?: CancellationToken): Promise<boolean> => {
// See if we can find the command
try {
const result = await this.findBestCommand(command, cancelToken);
return result !== undefined;
} catch (err) {
this.logger.logWarning(err);
return false;
}
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (inputEnv: NodeJS.ProcessEnv, interpreter: PythonInterpreter): Promise<any> => {
if (!inputEnv) {
inputEnv = process.env;
}
if (interpreter && interpreter.type === InterpreterType.Conda) {
return this.condaService.getActivatedCondaEnvironment(interpreter, inputEnv);
}
return inputEnv;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (info: PythonInterpreter | undefined, cancelToken?: CancellationToken): Promise<boolean> => {
if (info) {
// Enumerate our specs
const specs = await this.enumerateSpecs(cancelToken);
// See if any of their paths match
return specs.findIndex(s => {
if (info && s && s.path) {
return this.fileSystem.arePathsSame(s.path, info.path);
}
return false;
}) >= 0;
}
// If no active interpreter, just act like everything is okay as we can't find a new spec anyway
return true;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
s => {
if (info && s && s.path) {
return this.fileSystem.arePathsSame(s.path, info.path);
}
return false;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (enumerator: () => Promise<(IJupyterKernelSpec | undefined)[]>): Promise<IJupyterKernelSpec | undefined> => {
// Extract our current python information that the user has picked.
// We'll match against this.
const info = await this.interpreterService.getActiveInterpreter();
let bestScore = 0;
let bestSpec: IJupyterKernelSpec | undefined;
// Then enumerate our specs
const specs = await enumerator();
// For each get its details as we will likely need them
const specDetails = await Promise.all(specs.map(async s => {
if (s && s.path && s.path.length > 0 && await fs.pathExists(s.path)) {
return this.interpreterService.getInterpreterDetails(s.path);
}
}));
for (let i = 0; specs && i < specs.length; i += 1) {
const spec = specs[i];
let score = 0;
if (spec && spec.path && spec.path.length > 0 && info && spec.path === info.path) {
// Path match
score += 10;
}
if (spec && spec.language && spec.language.toLocaleLowerCase() === 'python') {
// Language match
score += 1;
// See if the version is the same
if (info && info.version && specDetails[i]) {
const details = specDetails[i];
if (details && details.version) {
if (details.version.major === info.version.major) {
// Major version match
score += 4;
if (details.version.minor === info.version.minor) {
// Minor version match
score += 2;
if (details.version.patch === info.version.patch) {
// Minor version match
score += 1;
}
}
}
}
} else if (info && info.version && spec && spec.path && spec.path.toLocaleLowerCase() === 'python' && spec.name) {
// This should be our current python.
// Search for a digit on the end of the name. It should match our major version
const match = /\D+(\d+)/.exec(spec.name);
if (match && match !== null && match.length > 0) {
// See if the version number matches
const nameVersion = parseInt(match[0], 10);
if (nameVersion && nameVersion === info.version.major) {
score += 4;
}
}
}
}
// Update high score
if (score > bestScore) {
bestScore = score;
bestSpec = spec;
}
}
// If still not set, at least pick the first one
if (!bestSpec && specs && specs.length > 0) {
bestSpec = specs[0];
}
return bestSpec;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async s => {
if (s && s.path && s.path.length > 0 && await fs.pathExists(s.path)) {
return this.interpreterService.getInterpreterDetails(s.path);
}
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (cancelToken?: CancellationToken): Promise<(IJupyterKernelSpec | undefined)[]> => {
if (await this.isKernelSpecSupported()) {
const kernelSpecCommand = await this.findBestCommand(KernelSpecCommand);
if (kernelSpecCommand) {
try {
// Ask for our current list.
const list = await kernelSpecCommand.exec(['list'], { throwOnStdErr: true, encoding: 'utf8' });
// This should give us back a key value pair we can parse
const lines = list.stdout.splitLines({ trim: false, removeEmptyEntries: true });
// Generate all of the promises at once
const promises = lines.map(l => this.readSpec(l));
// Then let them run concurrently (they are file io)
const specs = await Promise.all(promises);
return specs.filter(s => s);
} catch {
// This is failing for some folks. In that case return nothing
return [];
}
}
}
return [];
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
l => this.readSpec(l) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
s => s | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (command: string, interpreter: PythonInterpreter, cancelToken?: CancellationToken): Promise<JupyterCommand | undefined> => {
// If the module is found on this interpreter, then we found it.
if (interpreter && await this.doesModuleExist(command, interpreter, cancelToken) && !Cancellation.isCanceled(cancelToken)) {
// We need a process service to create a command
const processService = await this.processServicePromise;
// Our command args are different based on the command. ipykernel is not a jupyter command
const args = command === KernelCreateCommand ? ['-m', command] : ['-m', 'jupyter', command];
return new JupyterCommand(interpreter.path, args, processService, interpreter, this.condaService);
}
return undefined;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (pathToCheck: string): Promise<string[]> => {
try {
const files = await this.fileSystem.getFiles(pathToCheck);
return files ? files.filter(s => CheckJupyterRegEx.test(path.basename(s))) : [];
} catch (err) {
this.logger.logWarning('Python Extension (fileSystem.getFiles):', err);
}
return [] as string[];
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
s => CheckJupyterRegEx.test(path.basename(s)) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (): Promise<string | undefined> => {
if (!this.jupyterPath) {
const paths = this.knownSearchPaths.getSearchPaths();
for (let i = 0; i < paths.length && !this.jupyterPath; i += 1) {
const found = await this.lookForJupyterInDirectory(paths[i]);
if (found.length > 0) {
this.jupyterPath = found[0];
}
}
}
return this.jupyterPath;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (command: string, cancelToken?: CancellationToken): Promise<JupyterCommand | undefined> => {
if (await this.doesJupyterCommandExist(command, cancelToken) && !Cancellation.isCanceled(cancelToken)) {
// Search the known paths for jupyter
const jupyterPath = await this.searchPathsForJupyter();
if (jupyterPath) {
// We need a process service to create a command
const processService = await this.processServicePromise;
return new JupyterCommand(jupyterPath, [command], processService, this.interpreterService, this.condaService);
}
}
return undefined;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
async (command: string, cancelToken?: CancellationToken): Promise<JupyterCommand | undefined> => {
// See if we already have this command in list
if (!this.commands.hasOwnProperty(command)) {
// Not found, try to find it.
// First we look in the current interpreter
const current = await this.interpreterService.getActiveInterpreter();
let found = current ? await this.findInterpreterCommand(command, current, cancelToken) : undefined;
if (!found && this.supportsSearchingForCommands()) {
// Look through all of our interpreters (minus the active one at the same time)
const all = await this.interpreterService.getInterpreters();
const promises = all.filter(i => i !== current).map(i => this.findInterpreterCommand(command, i, cancelToken));
const foundList = await Promise.all(promises);
// Then go through all of the found ones and pick the closest python match
if (current && current.version) {
let bestScore = -1;
for (let i = 0; i < foundList.length; i += 1) {
let currentScore = 0;
if (foundList[i]) {
const interpreter = await foundList[i].interpreter();
const version = interpreter.version;
if (version) {
if (version.major === current.version.major) {
currentScore += 4;
if (version.minor === current.version.minor) {
currentScore += 2;
if (version.patch === current.version.patch) {
currentScore += 1;
}
}
}
}
if (currentScore > bestScore) {
found = foundList[i];
bestScore = currentScore;
}
}
}
} else {
// Just pick the first one
found = foundList.find(f => f !== undefined);
}
}
// If still not found, try looking on the path using jupyter
if (!found) {
found = await this.findPathCommand(command, cancelToken);
}
// If we found a command, save in our dictionary
if (found) {
this.commands[command] = found;
}
}
// Return result
return this.commands.hasOwnProperty(command) ? this.commands[command] : undefined;
} | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
i => i !== current | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
i => this.findInterpreterCommand(command, i, cancelToken) | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
ArrowFunction |
f => f !== undefined | Flamefire/vscode-python | src/client/datascience/jupyter/jupyterExecution.ts | TypeScript |
Subsets and Splits