type
stringclasses
7 values
content
stringlengths
4
9.55k
repo
stringlengths
7
96
path
stringlengths
4
178
language
stringclasses
1 value
ArrowFunction
() => { it('should create a new model file', async(() => { let b = new Blob( [`/**CTO File**/ namespace test`], {type: 'text/plain'} ); let file = new File([b], 'newfile.cto'); let dataBuffer = new Buffer('/**CTO File**/ namespace test'); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), 'models/' + file.name); mockClientService.createModelFile.returns(mockModel); // Run method component.createModel(file, dataBuffer); // Assertions component.fileType.should.equal('cto'); mockClientService.createModelFile.should.have.been.calledWith(dataBuffer.toString(), 'models/' + file.name); component.currentFile.should.deep.equal(mockModel); component.currentFileName.should.equal(mockModel.getName()); })); it('should use the addModelFileName variable as the file name if none passed in', async(() => { let fileName = 'models/testFileName.cto'; component.addModelFileName = fileName; let b = new Blob( [`/**CTO File**/ namespace test`], {type: 'text/plain'} ); let file = new File([b], ''); let dataBuffer = new Buffer('/**CTO File**/ namespace test'); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), fileName); mockClientService.createModelFile.returns(mockModel); // Run method component.createModel(null, dataBuffer); // Assertions component.fileType.should.equal('cto'); mockClientService.createModelFile.should.have.been.calledWith(dataBuffer.toString(), fileName); component.currentFile.should.deep.equal(mockModel); component.currentFileName.should.equal(mockModel.getName()); component.currentFileName.should.equal(fileName); })); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let b = new Blob( [`/**CTO File**/ namespace test`], {type: 'text/plain'} ); let file = new File([b], 'newfile.cto'); let dataBuffer = new Buffer('/**CTO File**/ namespace test'); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), 'models/' + file.name); mockClientService.createModelFile.returns(mockModel); // Run method component.createModel(file, dataBuffer); // Assertions component.fileType.should.equal('cto'); mockClientService.createModelFile.should.have.been.calledWith(dataBuffer.toString(), 'models/' + file.name); component.currentFile.should.deep.equal(mockModel); component.currentFileName.should.equal(mockModel.getName()); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let fileName = 'models/testFileName.cto'; component.addModelFileName = fileName; let b = new Blob( [`/**CTO File**/ namespace test`], {type: 'text/plain'} ); let file = new File([b], ''); let dataBuffer = new Buffer('/**CTO File**/ namespace test'); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), fileName); mockClientService.createModelFile.returns(mockModel); // Run method component.createModel(null, dataBuffer); // Assertions component.fileType.should.equal('cto'); mockClientService.createModelFile.should.have.been.calledWith(dataBuffer.toString(), fileName); component.currentFile.should.deep.equal(mockModel); component.currentFileName.should.equal(mockModel.getName()); component.currentFileName.should.equal(fileName); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { it('should create a new ACL file named permissions.acl', async(() => { let dataBuffer = new Buffer('/**RULE File**/ all the rules'); let filename = 'permissions.acl'; let mockRuleFile = sinon.createStubInstance(AclFile); mockClientService.createAclFile.returns(mockRuleFile); // Run method component.createRules(dataBuffer); // Assertions component.fileType.should.equal('acl'); mockClientService.createAclFile.should.have.been.calledWith(filename, dataBuffer.toString()); component.currentFile.should.deep.equal(mockRuleFile); component.currentFileName.should.equal(filename); })); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let dataBuffer = new Buffer('/**RULE File**/ all the rules'); let filename = 'permissions.acl'; let mockRuleFile = sinon.createStubInstance(AclFile); mockClientService.createAclFile.returns(mockRuleFile); // Run method component.createRules(dataBuffer); // Assertions component.fileType.should.equal('acl'); mockClientService.createAclFile.should.have.been.calledWith(filename, dataBuffer.toString()); component.currentFile.should.deep.equal(mockRuleFile); component.currentFileName.should.equal(filename); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { it('should create a new query file named queries.qry', async(() => { let dataBuffer = new Buffer('/**QUERY File**/ query things'); let filename = 'queries.qry'; mockClientService.createQueryFile.returns(mockQueryFile); // Run method component.createQuery(dataBuffer); // Assertions component.fileType.should.equal('qry'); mockClientService.createQueryFile.should.have.been.calledWith(filename, dataBuffer.toString()); component.currentFile.should.deep.equal(mockQueryFile); component.currentFileName.should.equal(filename); })); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let dataBuffer = new Buffer('/**QUERY File**/ query things'); let filename = 'queries.qry'; mockClientService.createQueryFile.returns(mockQueryFile); // Run method component.createQuery(dataBuffer); // Assertions component.fileType.should.equal('qry'); mockClientService.createQueryFile.should.have.been.calledWith(filename, dataBuffer.toString()); component.currentFile.should.deep.equal(mockQueryFile); component.currentFileName.should.equal(filename); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { it('should establish a readme file', async(() => { let dataBuffer = new Buffer('/**README File**/ read all the things'); // Run method component.createReadme(dataBuffer); // Assertions component.fileType.should.equal('md'); component.currentFileName.should.equal('README.md'); component.currentFile.should.equal(dataBuffer.toString()); })); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let dataBuffer = new Buffer('/**README File**/ read all the things'); // Run method component.createReadme(dataBuffer); // Assertions component.fileType.should.equal('md'); component.currentFileName.should.equal('README.md'); component.currentFile.should.equal(dataBuffer.toString()); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { it('should set current file to a script file, created by calling createScript with correct parameters', async(() => { let mockScript = sinon.createStubInstance(Script); mockScript.getIdentifier.returns('lib/script.js'); mockClientService.getScripts.returns([]); mockClientService.createScriptFile.returns(mockScript); component.fileType = 'js'; // Run method component.changeCurrentFileType(); // Assertions mockClientService.createScriptFile.getCall(0).args[0].should.equal('lib/script.js'); })); it('should increment a script file name if one already exists', async(() => { let mockScript = sinon.createStubInstance(Script); let mockScript0 = sinon.createStubInstance(Script); let mockScript1 = sinon.createStubInstance(Script); mockScript.getIdentifier.returns('lib/script.js'); mockScript0.getIdentifier.returns('lib/script0.js'); mockScript1.getIdentifier.returns('lib/script1.js'); mockClientService.getScripts.returns([mockScript, mockScript0, mockScript1]); mockClientService.createScriptFile.returns(mockScript); component.fileType = 'js'; // Run method component.changeCurrentFileType(); // Assertions mockClientService.createScriptFile.getCall(0).args[0].should.equal('lib/script2.js'); })); it('should change this.currentFileType to a cto file', async(() => { mockClientService.getModelFiles.returns([]); let b = new Blob( [`/** * New model file */ namespace org.acme.model`], {type: 'text/plain'} ); let file = new File([b], 'models/org.acme.model.cto'); let dataBuffer = new Buffer(`/** * New model file */ namespace org.acme.model`); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), file.name); mockClientService.createModelFile.returns(mockModel); component.fileType = 'cto'; // Run method component.changeCurrentFileType(); // Assertions component.currentFileName.should.equal('models/org.acme.model.cto'); component.currentFile.should.deep.equal(mockModel); })); it('should append the file number to the cto file name', () => { let b = new Blob( [`/** * New model file */ namespace org.acme.model`], {type: 'text/plain'} ); let file = new File([b], 'org.acme.model.cto'); let dataBuffer = new Buffer(`/** * New model file */ namespace org.acme.model`); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), file.name); // One element, so the number 0 should be appended mockClientService.getModelFiles.returns([mockModel]); component.fileType = 'cto'; // Run method component.changeCurrentFileType(); // Assertions mockClientService.createModelFile.getCall(0).args[1].should.be.equal('models/org.acme.model0.cto'); component.currentFileName.should.equal('models/org.acme.model0.cto'); }); it('should fill in template model name indices for a cto file name', async(() => { let mockFile = sinon.createStubInstance(ModelFile); mockFile.getNamespace.returns('org.acme.model'); let mockFile0 = sinon.createStubInstance(ModelFile); mockFile0.getNamespace.returns('org.acme.model0'); let mockFile1 = sinon.createStubInstance(ModelFile); mockFile1.getNamespace.returns('org.acme.model1'); let mockFile3 = sinon.createStubInstance(ModelFile); mockFile3.getNamespace.returns('org.acme.model3'); let mockFile4 = sinon.createStubInstance(ModelFile); mockFile4.getNamespace.returns('org.acme.model4'); mockClientService.getModelFiles.returns([mockFile, mockFile0, mockFile1, mockFile3, mockFile4]); let b = new Blob( [`/** * New model file */ namespace org.acme.model`], {type: 'text/plain'} ); let file = new File([b], 'org.acme.model.cto'); let dataBuffer = new Buffer(`/** * New model file */ namespace org.acme.model`); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), file.name); mockClientService.createModelFile.returns(mockModel); component.fileType = 'cto'; // Run method component.changeCurrentFileType(); // Assertions component.currentFileName.should.equal('models/org.acme.model2.cto'); })); it('should change current file to a query file upon calling createQueryFile', () => { let dataBuffer = new Buffer(`/** * New query file */`); let mockQuery = new QueryFile('queries.qry', mockQueryManager, dataBuffer.toString()); mockClientService.createAclFile.returns(mockQuery); component.fileType = 'qry'; component.changeCurrentFileType(); component.currentFileName.should.equal('queries.qry'); }); it('should change current file to an acl file upon calling createAclFile', () => { let dataBuffer = new Buffer(`/** * New access control file */ rule AllAccess { description: "AllAccess - grant everything to everybody." participant: "org.hyperledger.composer.system.Participant" operation: ALL resource: "org.hyperledger.composer.system.**" action: ALLOW }`); let mockAcl = new AclFile('permissions.acl', mockAclManager, dataBuffer.toString()); mockClientService.createAclFile.returns(mockAcl); component.fileType = 'acl'; component.changeCurrentFileType(); component.currentFileName.should.equal('permissions.acl'); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let mockScript = sinon.createStubInstance(Script); mockScript.getIdentifier.returns('lib/script.js'); mockClientService.getScripts.returns([]); mockClientService.createScriptFile.returns(mockScript); component.fileType = 'js'; // Run method component.changeCurrentFileType(); // Assertions mockClientService.createScriptFile.getCall(0).args[0].should.equal('lib/script.js'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let mockScript = sinon.createStubInstance(Script); let mockScript0 = sinon.createStubInstance(Script); let mockScript1 = sinon.createStubInstance(Script); mockScript.getIdentifier.returns('lib/script.js'); mockScript0.getIdentifier.returns('lib/script0.js'); mockScript1.getIdentifier.returns('lib/script1.js'); mockClientService.getScripts.returns([mockScript, mockScript0, mockScript1]); mockClientService.createScriptFile.returns(mockScript); component.fileType = 'js'; // Run method component.changeCurrentFileType(); // Assertions mockClientService.createScriptFile.getCall(0).args[0].should.equal('lib/script2.js'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { mockClientService.getModelFiles.returns([]); let b = new Blob( [`/** * New model file */ namespace org.acme.model`], {type: 'text/plain'} ); let file = new File([b], 'models/org.acme.model.cto'); let dataBuffer = new Buffer(`/** * New model file */ namespace org.acme.model`); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), file.name); mockClientService.createModelFile.returns(mockModel); component.fileType = 'cto'; // Run method component.changeCurrentFileType(); // Assertions component.currentFileName.should.equal('models/org.acme.model.cto'); component.currentFile.should.deep.equal(mockModel); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let b = new Blob( [`/** * New model file */ namespace org.acme.model`], {type: 'text/plain'} ); let file = new File([b], 'org.acme.model.cto'); let dataBuffer = new Buffer(`/** * New model file */ namespace org.acme.model`); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), file.name); // One element, so the number 0 should be appended mockClientService.getModelFiles.returns([mockModel]); component.fileType = 'cto'; // Run method component.changeCurrentFileType(); // Assertions mockClientService.createModelFile.getCall(0).args[1].should.be.equal('models/org.acme.model0.cto'); component.currentFileName.should.equal('models/org.acme.model0.cto'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let mockFile = sinon.createStubInstance(ModelFile); mockFile.getNamespace.returns('org.acme.model'); let mockFile0 = sinon.createStubInstance(ModelFile); mockFile0.getNamespace.returns('org.acme.model0'); let mockFile1 = sinon.createStubInstance(ModelFile); mockFile1.getNamespace.returns('org.acme.model1'); let mockFile3 = sinon.createStubInstance(ModelFile); mockFile3.getNamespace.returns('org.acme.model3'); let mockFile4 = sinon.createStubInstance(ModelFile); mockFile4.getNamespace.returns('org.acme.model4'); mockClientService.getModelFiles.returns([mockFile, mockFile0, mockFile1, mockFile3, mockFile4]); let b = new Blob( [`/** * New model file */ namespace org.acme.model`], {type: 'text/plain'} ); let file = new File([b], 'org.acme.model.cto'); let dataBuffer = new Buffer(`/** * New model file */ namespace org.acme.model`); let mockModel = new ModelFile(mockModelManager, dataBuffer.toString(), file.name); mockClientService.createModelFile.returns(mockModel); component.fileType = 'cto'; // Run method component.changeCurrentFileType(); // Assertions component.currentFileName.should.equal('models/org.acme.model2.cto'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let dataBuffer = new Buffer(`/** * New query file */`); let mockQuery = new QueryFile('queries.qry', mockQueryManager, dataBuffer.toString()); mockClientService.createAclFile.returns(mockQuery); component.fileType = 'qry'; component.changeCurrentFileType(); component.currentFileName.should.equal('queries.qry'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let dataBuffer = new Buffer(`/** * New access control file */ rule AllAccess { description: "AllAccess - grant everything to everybody." participant: "org.hyperledger.composer.system.Participant" operation: ALL resource: "org.hyperledger.composer.system.**" action: ALLOW }`); let mockAcl = new AclFile('permissions.acl', mockAclManager, dataBuffer.toString()); mockClientService.createAclFile.returns(mockAcl); component.fileType = 'acl'; component.changeCurrentFileType(); component.currentFileName.should.equal('permissions.acl'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { it('should reset back to default values', async(() => { component.expandInput = true; component.currentFile = true; component.currentFileName = true; component.fileType = 'js'; // Run method component.removeFile(); // Assertions component.expandInput.should.not.be.true; expect(component.currentFile).to.be.null; expect(component.currentFileName).to.be.null; component.fileType.should.equal(''); })); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { component.expandInput = true; component.currentFile = true; component.currentFileName = true; component.fileType = 'js'; // Run method component.removeFile(); // Assertions component.expandInput.should.not.be.true; expect(component.currentFile).to.be.null; expect(component.currentFileName).to.be.null; component.fileType.should.equal(''); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let file; let mockFileReadObj; let mockBuffer; let mockFileRead; let content; beforeEach(() => { content = 'hello world'; let data = new Blob([content], {type: 'text/plain'}); file = new File([data], 'mock.bna'); mockFileReadObj = { readAsArrayBuffer: sandbox.stub(), result: content, onload: sinon.stub(), onerror: sinon.stub() }; mockFileRead = sinon.stub(window, 'FileReader'); mockFileRead.returns(mockFileReadObj); }); afterEach(() => { mockFileRead.restore(); }); it('should return data from a file', () => { let promise = component.getDataBuffer(file); mockFileReadObj.onload(); return promise .then((data) => { // Assertions data.toString().should.equal(content); }); }); it('should give error in promise chain', () => { let promise = component.getDataBuffer(file); mockFileReadObj.onerror('error'); return promise .then((data) => { // Assertions data.should.be.null; }) .catch((err) => { // Assertions err.should.equal('error'); }); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { content = 'hello world'; let data = new Blob([content], {type: 'text/plain'}); file = new File([data], 'mock.bna'); mockFileReadObj = { readAsArrayBuffer: sandbox.stub(), result: content, onload: sinon.stub(), onerror: sinon.stub() }; mockFileRead = sinon.stub(window, 'FileReader'); mockFileRead.returns(mockFileReadObj); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { mockFileRead.restore(); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let promise = component.getDataBuffer(file); mockFileReadObj.onload(); return promise .then((data) => { // Assertions data.toString().should.equal(content); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
(data) => { // Assertions data.toString().should.equal(content); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let promise = component.getDataBuffer(file); mockFileReadObj.onerror('error'); return promise .then((data) => { // Assertions data.should.be.null; }) .catch((err) => { // Assertions err.should.equal('error'); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
(data) => { // Assertions data.should.be.null; }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
(err) => { // Assertions err.should.equal('error'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { it('should return true if an acl file is present', () => { let fileArray = []; fileArray.push({acl: true, id: 'acl file', displayID: 'acl0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); component['files'] = fileArray; let result = component['aclExists'](); result.should.equal(true); }); it('should return false if an acl file is not present', () => { let fileArray = []; fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script1'}); component['files'] = fileArray; let result = component['aclExists'](); result.should.equal(false); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let fileArray = []; fileArray.push({acl: true, id: 'acl file', displayID: 'acl0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); component['files'] = fileArray; let result = component['aclExists'](); result.should.equal(true); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let fileArray = []; fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script1'}); component['files'] = fileArray; let result = component['aclExists'](); result.should.equal(false); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { it('should return true if a query file is present', () => { let fileArray = []; fileArray.push({query: true, id: 'query file', displayID: 'query0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); component['files'] = fileArray; let result = component['queryExists'](); result.should.equal(true); }); it('should return true if a query file is not present', () => { let fileArray = []; fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script1'}); component['files'] = fileArray; let result = component['queryExists'](); result.should.equal(false); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let fileArray = []; fileArray.push({query: true, id: 'query file', displayID: 'query0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); component['files'] = fileArray; let result = component['queryExists'](); result.should.equal(true); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ArrowFunction
() => { let fileArray = []; fileArray.push({script: true, id: 'script 0', displayID: 'script0'}); fileArray.push({script: true, id: 'script 0', displayID: 'script1'}); component['files'] = fileArray; let result = component['queryExists'](); result.should.equal(false); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ClassDeclaration
class MockAdminService { getAdminConnection(): AdminConnection { return new AdminConnection(); } ensureConnection(): Promise<any> { return new Promise((resolve, reject) => { resolve(true); }); } deploy(): Promise<any> { return new Promise((resolve, reject) => { resolve(new BusinessNetworkDefinition('[email protected]', 'Acme Business Network')); }); } update(): Promise<any> { return new Promise((resolve, reject) => { resolve(new BusinessNetworkDefinition('[email protected]', 'Acme Business Network')); }); } generateDefaultBusinessNetwork(): BusinessNetworkDefinition { return new BusinessNetworkDefinition('[email protected]', 'Acme Business Network'); } isInitialDeploy(): boolean { return true; } }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
ClassDeclaration
class MockAlertService { public errorStatus$: Subject<string> = new BehaviorSubject<string>(null); public busyStatus$: Subject<string> = new BehaviorSubject<string>(null); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
MethodDeclaration
getAdminConnection(): AdminConnection { return new AdminConnection(); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
MethodDeclaration
ensureConnection(): Promise<any> { return new Promise((resolve, reject) => { resolve(true); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
MethodDeclaration
deploy(): Promise<any> { return new Promise((resolve, reject) => { resolve(new BusinessNetworkDefinition('[email protected]', 'Acme Business Network')); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
MethodDeclaration
update(): Promise<any> { return new Promise((resolve, reject) => { resolve(new BusinessNetworkDefinition('[email protected]', 'Acme Business Network')); }); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
MethodDeclaration
generateDefaultBusinessNetwork(): BusinessNetworkDefinition { return new BusinessNetworkDefinition('[email protected]', 'Acme Business Network'); }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
MethodDeclaration
isInitialDeploy(): boolean { return true; }
NunoEdgarGFlowHub/composer
packages/composer-playground/src/app/editor/add-file/add-file.component.spec.ts
TypeScript
FunctionDeclaration
export function queryEncode(data: Record<string, any>) { const queries: string[] = []; Object.entries(data).forEach(([key, value]) => { if (value !== undefined) { if (Array.isArray(value)) { value.forEach((val) => { queries.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`); }); } else { queries.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`); } } }); const result = queries.join('&'); return result ? '?' + result : ''; }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
FunctionDeclaration
export function queryDecode(url: string, forceArray = false) { const query = (url || '').substr(1); const result: Record<string, string | string[]> = {}; if (query) { query.split('&').forEach(function (part) { const item = part.split('='); const key = decodeURIComponent(item[0]); const value = decodeURIComponent(item[1]); if (result[key]) { if (Array.isArray(result[key])) { (result[key] as string[]).push(value); } else { result[key] = [result[key] as string, value]; } } else { if (forceArray) { result[key] = [value]; } else { result[key] = value; } } }); } return result; }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
ArrowFunction
([key, value]) => { if (value !== undefined) { if (Array.isArray(value)) { value.forEach((val) => { queries.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`); }); } else { queries.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`); } } }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
ArrowFunction
(val) => { queries.push(`${encodeURIComponent(key)}=${encodeURIComponent(val)}`); }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
ArrowFunction
( key: string, options?: Options ): [ string | string[] | undefined, (value: string | string[] | undefined) => void ] => { const location = useLocation(); const value = queryDecode(location.search)[key]; const { replace, push } = useHistory(); const getNewSearch = useCallback( (value: any) => { const data = queryDecode(window.location.search); const newValue = value === options?.defaultVal ? undefined : value; const newSearch = queryEncode({ ...data, [key]: newValue, }); return newSearch; }, [options?.defaultVal] ); const setState = useCallback( (value: any) => { const newSearch = getNewSearch(value); if (options?.history) { push(window.location.pathname + newSearch); } else { replace(window.location.pathname + newSearch); } }, [getNewSearch] ); useEffect(() => { return () => { if (options?.cleanup) { setState(undefined); } }; }, [setState]); if (!options?.array) { return [value === undefined ? options?.defaultVal : value, setState]; } else { return [ Array.isArray(value) ? value : value !== undefined ? [value] : [], setState, ]; } }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
ArrowFunction
(value: any) => { const data = queryDecode(window.location.search); const newValue = value === options?.defaultVal ? undefined : value; const newSearch = queryEncode({ ...data, [key]: newValue, }); return newSearch; }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
ArrowFunction
(value: any) => { const newSearch = getNewSearch(value); if (options?.history) { push(window.location.pathname + newSearch); } else { replace(window.location.pathname + newSearch); } }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
ArrowFunction
() => { return () => { if (options?.cleanup) { setState(undefined); } }; }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
ArrowFunction
() => { if (options?.cleanup) { setState(undefined); } }
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
TypeAliasDeclaration
type Options = { defaultVal?: string | string[]; history?: boolean; array?: boolean; // clear parameter from url, after unmount cleanup?: boolean; };
Tolgee/server
webapp/src/hooks/useUrlSearchState.ts
TypeScript
InterfaceDeclaration
export interface ictx extends RouterContext { session: iSession; }
cuo9958/nps-cms
src/extends.ts
TypeScript
InterfaceDeclaration
interface iSession { user: IUser; }
cuo9958/nps-cms
src/extends.ts
TypeScript
InterfaceDeclaration
interface IUser { id: number; user_type: number; username: string; nickname: string; uuid: string; }
cuo9958/nps-cms
src/extends.ts
TypeScript
FunctionDeclaration
function readFiles (sourcePath, originalFilePath) { readPromises.push(new Promise((resolve, reject) => { klaw(sourcePath) .on('data', file => { const REG_IGNORE = /(\\|\/)\.(svn|git)\1/i; const relativePath = path.relative(appPath, file.path) if (file.stats.isSymbolicLink()) { let linkFile = fs.readlinkSync(file.path) if (!path.isAbsolute(linkFile)) { linkFile = path.resolve(file.path, '..', linkFile) } readFiles.call(this, linkFile, file.path) } else if (!file.stats.isDirectory() && !REG_IGNORE.test(relativePath)) { printLog(processTypeEnum.CREATE, '发现文件', relativePath) this.processFiles(file.path, originalFilePath) } }) .on('end', () => { resolve() }) })) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
FunctionDeclaration
export async function build (appPath: string, buildConfig: IBuildOptions, buildHooks: IBuildHooks) { process.env.TARO_ENV = 'h5' await checkCliAndFrameworkVersion(appPath, 'h5') const compiler = new Compiler(appPath) await compiler.clean() await compiler.buildTemp() if (compiler.h5Config.transformOnly !== true) { await compiler.buildDist(buildConfig, buildHooks) } if (buildConfig.watch) { compiler.watchFiles() } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
filePath => filePath.indexOf(path.dirname(path.join(appPath, PROJECT_CONFIG))) >= 0
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
([pageName, filePath]) => { const relPage = path.normalize( path.relative(appPath, pageName) ) if (path.relative(relPage, relSrcPath) === '') return true return false }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(resolve, reject) => { klaw(sourcePath) .on('data', file => { const REG_IGNORE = /(\\|\/)\.(svn|git)\1/i; const relativePath = path.relative(appPath, file.path) if (file.stats.isSymbolicLink()) { let linkFile = fs.readlinkSync(file.path) if (!path.isAbsolute(linkFile)) { linkFile = path.resolve(file.path, '..', linkFile) } readFiles.call(this, linkFile, file.path) } else if (!file.stats.isDirectory() && !REG_IGNORE.test(relativePath)) { printLog(processTypeEnum.CREATE, '发现文件', relativePath) this.processFiles(file.path, originalFilePath) } }) .on('end', () => { resolve() }) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
file => { const REG_IGNORE = /(\\|\/)\.(svn|git)\1/i; const relativePath = path.relative(appPath, file.path) if (file.stats.isSymbolicLink()) { let linkFile = fs.readlinkSync(file.path) if (!path.isAbsolute(linkFile)) { linkFile = path.resolve(file.path, '..', linkFile) } readFiles.call(this, linkFile, file.path) } else if (!file.stats.isDirectory() && !REG_IGNORE.test(relativePath)) { printLog(processTypeEnum.CREATE, '发现文件', relativePath) this.processFiles(file.path, originalFilePath) } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
() => { resolve() }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(filename: string) => { return path.join(tempPath, filename) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
([pagename, filePath]) => { return [filePath, [getEntryFile(filePath) + '.js']] }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
filePath => { const relativePath = path.relative(appPath, filePath) printLog(processTypeEnum.CREATE, '添加文件', relativePath) this.processFiles(filePath, filePath) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
filePath => { const relativePath = path.relative(appPath, filePath) printLog(processTypeEnum.MODIFY, '文件变动', relativePath) this.processFiles(filePath, filePath) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
filePath => { const relativePath = path.relative(appPath, filePath) const extname = path.extname(relativePath) const distDirname = this.getTempDir(filePath, filePath) const isScriptFile = REG_SCRIPTS.test(extname) const dist = this.getDist(distDirname, filePath, isScriptFile) printLog(processTypeEnum.UNLINK, '删除文件', relativePath) fs.unlinkSync(dist) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(currentPagename: string, funcBody: string) => { const firstPage = first(pages) const homePage = firstPage ? firstPage[0] : '' const panel = ` <${tabBarPanelComponentName}> ${funcBody} </${tabBarPanelComponentName}>` const comp = ` <${tabBarComponentName} conf={this.state.${tabBarConfigName}} homePage="${homePage}" ${currentPagename ? `currentPagename={'${currentPagename}'}` : ''} ${tabbarPos === 'top' ? `tabbarPos={'top'}` : ''} />` return ` <${tabBarContainerComponentName}> ${tabbarPos === 'top' ? `${comp}${panel}` : `${panel}${comp}`} </${tabBarContainerComponentName}>` }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(funcBody: string) => { return ` <${providerImportName} store={${storeName}}> ${funcBody} </${providerImportName}> ` }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(funcBody: string) => { return `{return (${funcBody});}` }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(pages: [PageName, FilePath][]) => { const routes = pages.map(([pageName, filePath], k) => { const shouldLazyloadPage = typeof routerLazyload === 'function' ? routerLazyload(pageName) : routerLazyload return createRoute({ pageName, lazyload: shouldLazyloadPage, isIndex: k === 0 }) }) return ` <Router mode={${JSON.stringify(routerMode)}} history={_taroHistory} routes={[${routes.join(',')}]} ${tabBar ? `tabBar={this.state.${tabBarConfigName}}` : ''} customRoutes={${JSON.stringify(customRoutes)}} /> ` }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
([pageName, filePath], k) => { const shouldLazyloadPage = typeof routerLazyload === 'function' ? routerLazyload(pageName) : routerLazyload return createRoute({ pageName, lazyload: shouldLazyloadPage, isIndex: k === 0 }) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
v => { if (t.isSpreadProperty(v)) return false return toVar(v.key) === 'root' }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(v: t.StringLiteral) => { const pagePath = `${root}/${v.value}`.replace(/\/{2,}/g, '/') const pageName = removeLeadingSlash(pagePath) pages.push([pageName, renamePagename(pageName).replace(/\//g, '')]) v.value = addLeadingSlash(v.value) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(v: t.StringLiteral) => { const pagePath = v.value.replace(/\/{2,}/g, '/') const pageName = removeLeadingSlash(pagePath) pages.push([pageName, renamePagename(pageName).replace(/\//g, '')]) v.value = addLeadingSlash(v.value) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(node) => { if (t.isSpreadProperty(node)) return switch (toVar(node.key)) { case 'position': tabbarPos = toVar(node.value) break case 'list': t.isArrayExpression(node.value) && node.value.elements.forEach(v => { if (!t.isObjectExpression(v)) return v.properties.forEach(property => { if (!t.isObjectProperty(property)) return switch (toVar(property.key)) { case 'iconPath': case 'selectedIconPath': if (t.isStringLiteral(property.value)) { property.value = t.callExpression( t.identifier('require'), [t.stringLiteral(`./${property.value.value}`)] ) } break case 'pagePath': property.value = t.stringLiteral(addLeadingSlash(toVar(property.value))) break } }) }) } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
v => { if (!t.isObjectExpression(v)) return v.properties.forEach(property => { if (!t.isObjectProperty(property)) return switch (toVar(property.key)) { case 'iconPath': case 'selectedIconPath': if (t.isStringLiteral(property.value)) { property.value = t.callExpression( t.identifier('require'), [t.stringLiteral(`./${property.value.value}`)] ) } break case 'pagePath': property.value = t.stringLiteral(addLeadingSlash(toVar(property.value))) break } }) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
property => { if (!t.isObjectProperty(property)) return switch (toVar(property.key)) { case 'iconPath': case 'selectedIconPath': if (t.isStringLiteral(property.value)) { property.value = t.callExpression( t.identifier('require'), [t.stringLiteral(`./${property.value.value}`)] ) } break case 'pagePath': property.value = t.stringLiteral(addLeadingSlash(toVar(property.value))) break } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(res, [pageName, filePath], key) => { res[addLeadingSlash(pageName)] = addLeadingSlash(filePath) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(astPath: NodePath<t.ImportDeclaration>) => { const node = astPath.node const source = node.source const specifiers = node.specifiers if (source.value === '@tarojs/taro') { const specifier = specifiers.find(item => t.isImportDefaultSpecifier(item)) if (specifier) { taroImportDefaultName = toVar(specifier.local) } source.value = '@tarojs/taro-h5' } else if (source.value === '@tarojs/redux') { const specifier = specifiers.find(item => { return t.isImportSpecifier(item) && item.imported.name === providerComponentName }) if (specifier) { providerImportName = specifier.local.name } else { providerImportName = providerComponentName specifiers.push(t.importSpecifier(t.identifier(providerComponentName), t.identifier(providerComponentName))) } source.value = '@tarojs/redux-h5' } else if (source.value === '@tarojs/mobx') { const specifier = specifiers.find(item => { return t.isImportSpecifier(item) && item.imported.name === providerComponentName }) if (specifier) { providerImportName = specifier.local.name } else { providerImportName = providerComponentName specifiers.push(t.importSpecifier(t.identifier(providerComponentName), t.identifier(providerComponentName))) } source.value = '@tarojs/mobx-h5' } else if (source.value === 'nervjs') { hasNerv = true const defaultSpecifier = specifiers.find(item => t.isImportDefaultSpecifier(item)) if (!defaultSpecifier) { specifiers.unshift( t.importDefaultSpecifier(t.identifier(nervJsImportDefaultName)) ) } } if (isAliasPath(source.value, pathAlias)) { source.value = this.transformToTempDir(replaceAliasPath(filePath, source.value, pathAlias)) } if (!isNpmPkg(source.value)) { if (source.value.indexOf('.') === 0) { const pathArr = source.value.split('/') /* FIXME: 会导致误删除 */ if (pathArr.indexOf('pages') >= 0) { astPath.remove() } else if (REG_SCRIPTS.test(source.value) || path.extname(source.value) === '') { /* 移除后缀名 */ const absolutePath = path.resolve(filePath, '..', source.value) const dirname = path.dirname(absolutePath) const extname = path.extname(absolutePath) const realFilePath = resolveScriptPath(path.join(dirname, path.basename(absolutePath, extname))) const removeExtPath = realFilePath.replace(path.extname(realFilePath), '') source.value = promoteRelativePath(path.relative(filePath, removeExtPath)).replace(/\\/g, '/') } } } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
item => t.isImportDefaultSpecifier(item)
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
item => { return t.isImportSpecifier(item) && item.imported.name === providerComponentName }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(ast) => { return generate(ast, { jsescOption: { minimal: true } }).code }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
([pageName, filePath], k) => { const createFuncBody = () => { const shouldLazyloadPage = typeof routerLazyload === 'function' ? routerLazyload(pageName) : routerLazyload const route = createRoute({ pageName, lazyload: shouldLazyloadPage, isIndex: k === 0 }) return ` <Router mode={${JSON.stringify(routerMode)}} history={_taroHistory} routes={[${route}]} ${tabBar ? `tabBar={this.state.${tabBarConfigName}}` : ''} customRoutes={${JSON.stringify(customRoutes)}} /> ` } const replaceMultiRouterVisitor: TraverseOptions<t.Node> = { ClassMethod: { exit (astPath: NodePath<t.ClassMethod>) { const node = astPath.node const key = node.key const keyName = toVar(key) const isRender = keyName === 'render' const isComponentWillMount = keyName === 'componentWillMount' const isComponentDidMount = keyName === 'componentDidMount' const isComponentWillUnmount = keyName === 'componentWillUnmount' const isConstructor = keyName === 'constructor' if (isRender) { const buildFuncBody = pipe( ...compact([ createFuncBody, tabBar && partial(wrapWithTabbar, [addLeadingSlash(pageName)]), providerComponentName && storeName && wrapWithProvider, wrapWithFuncBody ]) ) node.body = toAst(buildFuncBody(pages), { preserveComments: true }) } else { node.body.body = compact([ hasComponentDidHide && isComponentWillUnmount && callComponentDidHideNode, ...node.body.body, tabBar && isComponentWillMount && initTabbarApiNode, hasConstructor && isConstructor && additionalConstructorNode, hasComponentDidShow && isComponentDidMount && callComponentDidShowNode ]) } } }, Program: { exit (astPath: NodePath<t.Program>) { const node = astPath.node node.body.forEach((bodyNode) => { if (t.isExpressionStatement(bodyNode) && t.isCallExpression(bodyNode.expression) && t.isIdentifier(bodyNode.expression.callee) && bodyNode.expression.callee.name === 'mountApis') { const mountApisOptNode = bodyNode.expression.arguments[0] if (t.isObjectExpression(mountApisOptNode)) { const valueNode = t.stringLiteral(addLeadingSlash(pageName)) let basenameNode = mountApisOptNode.properties.find((property: t.ObjectProperty) => { return toVar<string>(property.key) === 'currentPagename' }) as t.ObjectProperty | undefined if (basenameNode) { basenameNode.value = valueNode } else { basenameNode = t.objectProperty(t.stringLiteral('currentPagename'), valueNode) mountApisOptNode.properties.push(basenameNode) } } } }) } } } traverse(ast, replaceMultiRouterVisitor) return [filePath, generateCode(ast)] }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
() => { const shouldLazyloadPage = typeof routerLazyload === 'function' ? routerLazyload(pageName) : routerLazyload const route = createRoute({ pageName, lazyload: shouldLazyloadPage, isIndex: k === 0 }) return ` <Router mode={${JSON.stringify(routerMode)}} history={_taroHistory} routes={[${route}]} ${tabBar ? `tabBar={this.state.${tabBarConfigName}}` : ''} customRoutes={${JSON.stringify(customRoutes)}} /> ` }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(bodyNode) => { if (t.isExpressionStatement(bodyNode) && t.isCallExpression(bodyNode.expression) && t.isIdentifier(bodyNode.expression.callee) && bodyNode.expression.callee.name === 'mountApis') { const mountApisOptNode = bodyNode.expression.arguments[0] if (t.isObjectExpression(mountApisOptNode)) { const valueNode = t.stringLiteral(addLeadingSlash(pageName)) let basenameNode = mountApisOptNode.properties.find((property: t.ObjectProperty) => { return toVar<string>(property.key) === 'currentPagename' }) as t.ObjectProperty | undefined if (basenameNode) { basenameNode.value = valueNode } else { basenameNode = t.objectProperty(t.stringLiteral('currentPagename'), valueNode) mountApisOptNode.properties.push(basenameNode) } } } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(property: t.ObjectProperty) => { return toVar<string>(property.key) === 'currentPagename' }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(componentName: string, node: t.JSXOpeningElement) => { const idAttrName = MAP_FROM_COMPONENTNAME_TO_ID.get(componentName) return node.attributes.reduce((prev, attribute) => { if (prev) return prev const attrName = toVar(attribute.name) if (attrName === idAttrName) return toVar(attribute.value) else return false }, false as string | false) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(prev, attribute) => { if (prev) return prev const attrName = toVar(attribute.name) if (attrName === idAttrName) return toVar(attribute.value) else return false }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(node: t.JSXOpeningElement) => { return node.attributes.find(attribute => { return toVar(attribute.name) === 'ref' }) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
attribute => { return toVar(attribute.name) === 'ref' }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(componentId: string) => { return t.arrowFunctionExpression( [t.identifier('ref')], t.blockStatement([ toAst(`this['__taroref_${componentId}'] = ref`) as t.Statement ]) ) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(astPath: NodePath<t.ExportNamedDeclaration>) => { if (!astPath) return const node = astPath.node if (t.isFunctionDeclaration(node.declaration)) { astPath.replaceWithMultiple([ node.declaration, t.exportDefaultDeclaration(node.declaration.id) ]) } else if (t.isClassDeclaration(node.declaration)) { astPath.replaceWithMultiple([ node.declaration, t.exportDefaultDeclaration(node.declaration.id) ]) } else if (t.isVariableDeclaration(node.declaration)) { const declarationId = node.declaration.declarations[0].id if (t.isIdentifier(declarationId)) { astPath.replaceWithMultiple([ node.declaration, t.exportDefaultDeclaration(declarationId) ]) } } else if (node.specifiers && node.specifiers.length) { astPath.replaceWithMultiple([ t.exportDefaultDeclaration(node.specifiers[0].local) ]) } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(astPath: NodePath<t.ImportDeclaration>) => { const node = astPath.node const source = node.source const specifiers = node.specifiers if (source.value === '@tarojs/taro') { importTaroNode = node specifiers.forEach(specifier => { if (t.isImportDefaultSpecifier(specifier)) { taroImportDefaultName = toVar(specifier.local) } else if (t.isImportSpecifier(specifier)) { taroapiMap.set(toVar(specifier.local), toVar(specifier.imported)) } }) source.value = '@tarojs/taro-h5' } else if (source.value === '@tarojs/redux') { source.value = '@tarojs/redux-h5' } else if (source.value === '@tarojs/mobx') { source.value = '@tarojs/mobx-h5' } else if (source.value === '@tarojs/components') { importTaroComponentNode = node node.specifiers.forEach((specifier) => { if (!t.isImportSpecifier(specifier)) return componentnameMap.set(toVar(specifier.local), toVar(specifier.imported)) }) } else if (source.value === 'nervjs') { importNervNode = node } if (isAliasPath(source.value, pathAlias)) { source.value = this.transformToTempDir(replaceAliasPath(filePath, source.value, pathAlias)) } if (!isNpmPkg(source.value)) { if (REG_SCRIPTS.test(source.value) || path.extname(source.value) === '') { const absolutePath = path.resolve(filePath, '..', source.value) const dirname = path.dirname(absolutePath) const extname = path.extname(absolutePath) const realFilePath = resolveScriptPath(path.join(dirname, path.basename(absolutePath, extname))) const removeExtPath = realFilePath.replace(path.extname(realFilePath), '') source.value = promoteRelativePath(path.relative(filePath, removeExtPath)).replace(/\\/g, '/') } } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
specifier => { if (t.isImportDefaultSpecifier(specifier)) { taroImportDefaultName = toVar(specifier.local) } else if (t.isImportSpecifier(specifier)) { taroapiMap.set(toVar(specifier.local), toVar(specifier.imported)) } }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(specifier) => { if (!t.isImportSpecifier(specifier)) return componentnameMap.set(toVar(specifier.local), toVar(specifier.imported)) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
(p: NodePath<t.Node>) => p.isClassExpression() || p.isClassDeclaration()
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
specifier => { if (!t.isImportSpecifier(specifier)) return false const importedComponent = toVar(specifier.imported) return importedComponent === 'PullDownRefresh' }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
renderReturnStatementPath => { const funcParentPath: NodePath = renderReturnStatementPath.getFunctionParent() return funcParentPath.node === renderClassMethodNode }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
returnAstPath => { const statement = returnAstPath.node const varName = returnAstPath.scope.generateUid() const returnValue = statement.argument const pullDownRefreshNode = t.variableDeclaration( 'const', [t.variableDeclarator( t.identifier(varName), returnValue )] ) returnAstPath.insertBefore(pullDownRefreshNode) statement.argument = (toAst(` <PullDownRefresh onRefresh={this.onPullDownRefresh && this.onPullDownRefresh.bind(this)} ref={ref => { if (ref) this.pullDownRefreshRef = ref }}>{${varName}}</PullDownRefresh>`) as t.ExpressionStatement).expression }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript
ArrowFunction
([pageName, code]) => { fs.writeFileSync( path.join(distDirname, `${pageName}.js`), code ) }
CooperFu/taro
packages/taro-cli/src/h5/index.ts
TypeScript