Skip to content

Commit ad780b8

Browse files
committed
move output parsing into its own function
1 parent 9f5e572 commit ad780b8

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/parser.ts

+29-14
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,8 @@ export const parser = (filePaths: Array<string>): Array<File> => {
5555
logger.log("Selector:", selector);
5656
}
5757

58-
let inputs: Array<Input> = parseInputs(file);
59-
60-
let outputs: Array<Output> = [];
61-
// only @Output() buttonClick: EventEmitter<any> = new EventEmitter(); for now
62-
let outputsData: Array<string> = file?.match(REGEX_SELECTORS.regularOutputSelector) || [];
63-
for (let output of outputsData) {
64-
let tmp: Array<string> = output.replace(/(\s+)/g, " ").split(" ");
65-
outputs.push({
66-
outputName: tmp[1].replace(":", ""),
67-
type: tmp[2].substr(tmp[2].indexOf("<"), tmp[2].indexOf(">")).replace(">", "").replace("<", ""),
68-
});
69-
}
70-
file = file.replace(REGEX_SELECTORS.regularOutputSelector, "");
71-
logger.log("Outputs detected:", outputs);
58+
let inputs: Array<Input> = parseInputs(file),
59+
outputs: Array<Output> = parseOutputs(file);
7260

7361
let extendedClassPath;
7462
if (file?.match(REGEX_SELECTORS.extendedClassSelector)) {
@@ -127,6 +115,11 @@ export const parser = (filePaths: Array<string>): Array<File> => {
127115
return result;
128116
};
129117

118+
/**
119+
* @private
120+
* @param {string} file a string where to look for input definitions
121+
* @returns {Array<Input>} An array containing all the inputs defined in the given string
122+
*/
130123
const parseInputs = (file: string): Array<Input> => {
131124
// notice we ignore the default value of the input in the regex
132125
// Input() foo: 'type1' | 'type2'
@@ -246,3 +239,25 @@ const parseInputs = (file: string): Array<Input> => {
246239
logger.log("Inputs detected:", inputs);
247240
return inputs;
248241
};
242+
243+
/**
244+
* @private
245+
* @param {string} file a string where to look for output definitions
246+
* @returns {Array<Input>} An array containing all the outputs defined in the given string
247+
*/
248+
const parseOutputs = (file: string): Array<Output> => {
249+
let outputs: Array<Output> = [];
250+
// only @Output() buttonClick: EventEmitter<any> = new EventEmitter(); for now
251+
let outputsData: Array<string> = file?.match(REGEX_SELECTORS.regularOutputSelector) || [];
252+
for (let output of outputsData) {
253+
let tmp: Array<string> = output.replace(/(\s+)/g, " ").split(" ");
254+
outputs.push({
255+
outputName: tmp[1].replace(":", ""),
256+
type: tmp[2].substr(tmp[2].indexOf("<"), tmp[2].indexOf(">")).replace(">", "").replace("<", ""),
257+
});
258+
}
259+
file = file.replace(REGEX_SELECTORS.regularOutputSelector, "");
260+
logger.log("Outputs detected:", outputs);
261+
262+
return outputs;
263+
};

0 commit comments

Comments
 (0)