Skip to content

Commit

Permalink
refactor: 调整link实现。
Browse files Browse the repository at this point in the history
  • Loading branch information
黄健 committed Dec 1, 2016
1 parent a34c657 commit 1ff613b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
7 changes: 0 additions & 7 deletions analyzer.type.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
* @property {string} type - ES6 import style, default or destruct
*/

/**
* @typedef {object} TemplateDescriptor
*
* @property {string} location - import file source path
* @property {string} category - only support template
*/

/**
* @typedef {object} NgDescriptor
*
Expand Down
35 changes: 15 additions & 20 deletions test/link.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,30 @@ const { linkAnalyzeStream, cleanAnalyzeStream } = require('../src/link');

describe('ng-hot-analyze link', function () {
it('should link analyze stream', function () {
let componentAccessToken = [{ token: 'bkPrompt', name: 'promptFactory', category: 'factory' }];
let componentInstanceReference = [
let instanceReferenceList = [
{ location: './service/prompt.factory', name: 'promptFactory', type: 'destruct' },
{ location: './filter/postfix.filter', name: 'postfixFilter', type: 'destruct' }
{ location: './template/todo.html', name: 'todoPageTemplate', type: 'default' }
];

let [prompt, postfix] = linkAnalyzeStream(componentInstanceReference, componentAccessToken);
let accessTokenList = [
{ token: 'bkPrompt', name: 'promptFactory', category: 'factory' },
{ token: 'RouteMark', name: 'todoPageTemplate', category: 'RouteTemplate' }
];

prompt.should.eql({
name: 'promptFactory',
token: 'bkPrompt',
category: 'factory',
location: './service/prompt.factory',
type: 'destruct'
});
let [prompt, todo] = linkAnalyzeStream(instanceReferenceList, accessTokenList);

// ignore none-match reference
postfix.should.eql(componentInstanceReference[1]);
prompt.should.eql(Object.assign({}, instanceReferenceList[0], { token: 'bkPrompt', category: 'factory' }));
todo.should.eql(Object.assign({}, instanceReferenceList[1], { token: 'RouteMark', category: 'RouteTemplate' }));
});

it('should clean unnecessary stream', function () {
let componentAccessToken = [{ token: 'bkPrompt', name: 'promptFactory', category: 'factory' }];
let componentInstanceReference = [
it('should clean unnecessary reference', function () {
let list = [
{ token: 'bkPrompt', name: 'promptFactory', category: 'factory' },
{ location: './service/prompt.factory', name: 'promptFactory', type: 'destruct' },
{ location: './filter/postfix.filter', name: 'postfixFilter', type: 'destruct' }
{ location: './filter/postfix.filter', name: 'postfixFilter', type: 'destruct' },
{ token: 'bkPrompt', location: './filter/postfix.filter', name: 'promptFactory' }
];

let pristine = cleanAnalyzeStream(linkAnalyzeStream(componentInstanceReference, componentAccessToken));

pristine.length.should.equal(1);
cleanAnalyzeStream(list).should.eql([list[3]]);
});
});

0 comments on commit 1ff613b

Please sign in to comment.