Comparing version 0.2.0 to 0.2.1
@@ -289,3 +289,3 @@ (function () { | ||
return '\n var ' + importedThings.map(function (importedThing) { | ||
return (importedThing.defaultImportName ? importedThing.defaultImportName : '') + importedThing.namedImports.map(function (namedImport) { | ||
return (importedThing.defaultImportName ? importedThing.defaultImportName : '') + (importedThing.defaultImportName && importedThing.namedImports && importedThing.namedImports.length > 0 ? ', ' : '') + importedThing.namedImports.map(function (namedImport) { | ||
return namedImport.alias ? namedImport.alias : namedImport.name; | ||
@@ -530,16 +530,18 @@ }); | ||
} | ||
} else if (/\s/.test(char) && lookingFor === 'DEFAULT_IMPORT_VAR_NAME') { | ||
// console.log('found default import name ' + currentWord); | ||
defaultImportName = currentWord$1.substring(0, currentWord$1.length - 1); | ||
resetWord$1(); | ||
if (namedImports === null) { | ||
// console.log('looking for named imports') | ||
lookingFor = 'NAMED_IMPORTS'; | ||
} else { | ||
// console.log('looking for ') | ||
lookingFor = 'FROM_KEYWORD'; | ||
} else if (lookingFor === 'DEFAULT_IMPORT_VAR_NAME') { | ||
if (/\s/.test(char) || char === ',') { | ||
// console.log(`found default import name '${currentWord}'`); | ||
defaultImportName = currentWord$1.substring(0, currentWord$1.length - 1); | ||
resetWord$1(); | ||
if (namedImports === null) { | ||
// console.log('looking for named imports') | ||
lookingFor = 'NAMED_IMPORTS'; | ||
} else { | ||
// console.log('looking for FROM_KEYWORD') | ||
lookingFor = 'FROM_KEYWORD'; | ||
} | ||
} | ||
} else if (lookingFor === 'NAMED_IMPORTS') { | ||
if (char === '{') { | ||
nameImports = []; | ||
namedImports = []; | ||
resetWord$1(); | ||
@@ -559,2 +561,3 @@ lookingFor = 'VARIABLE_LIST'; | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
lookingFor = 'NAMED_IMPORTS_COMMA'; | ||
@@ -569,5 +572,11 @@ } | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
} | ||
resetWord$1(); | ||
lookingFor = 'FROM_KEYWORD'; | ||
if (defaultImportName) { | ||
lookingFor = 'FROM_KEYWORD'; | ||
} else { | ||
// console.log('looking for imported vars') | ||
lookingFor = 'IMPORTED_VARS'; | ||
} | ||
} else if (char === ',') { | ||
@@ -579,2 +588,3 @@ // console.log('looking for named imports'); | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
} | ||
@@ -597,4 +607,10 @@ resetWord$1(); | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
} | ||
lookingFor = 'FROM_KEYWORD'; | ||
if (defaultImportName) { | ||
lookingFor = 'FROM_KEYWORD'; | ||
} else { | ||
// console.log('looking for DEFAULT_IMPORT_COMMA ') | ||
lookingFor = 'DEFAULT_IMPORT_COMMA'; | ||
} | ||
resetWord$1(); | ||
@@ -604,2 +620,18 @@ } else { | ||
} | ||
} else if (lookingFor === 'DEFAULT_IMPORT_COMMA') { | ||
if (char === ',') { | ||
// console.log('looking for DEFAULT_IMPORT_VAR_NAME') | ||
lookingFor = 'DEFAULT_IMPORT_VAR_WHITESPACE'; | ||
resetWord$1(); | ||
} else if (/\s/.test(char)) { | ||
resetWord$1(); | ||
} else { | ||
lookingFor = 'FROM_KEYWORD'; | ||
} | ||
} else if (lookingFor === 'DEFAULT_IMPORT_VAR_WHITESPACE') { | ||
if (!/\s/.test(char)) { | ||
lookingFor = 'DEFAULT_IMPORT_VAR_NAME'; | ||
} else { | ||
resetWord$1(); | ||
} | ||
} else if (lookingFor === 'FROM_KEYWORD') { | ||
@@ -627,20 +659,24 @@ if (currentWord$1 === 'from') { | ||
} | ||
} else if (char === moduleIdentifierDelimiter) { | ||
lookingFor = 'END_OF_STATEMENT'; | ||
moduleIdentifier = currentWord$1.substring(0, currentWord$1.length - 1); | ||
// console.log('looking for end of statement') | ||
} else if (lookingFor === 'MODULE_IDENTIFIER') { | ||
// console.log(`module identifier '${currentWord}'`) | ||
if (char === moduleIdentifierDelimiter) { | ||
// console.log('looking for end of statement') | ||
lookingFor = 'END_OF_STATEMENT'; | ||
moduleIdentifier = currentWord$1.substring(0, currentWord$1.length - 1); | ||
} | ||
} else if (lookingFor === 'END_OF_STATEMENT') { | ||
if (!(char === ';' || /\s/.test(char))) { | ||
//we have reached the end of the import statement | ||
imports.push({ | ||
moduleIdentifier: moduleIdentifier, | ||
defaultImportName: defaultImportName, | ||
namedImports: namedImports || [], | ||
startIndex: startIndex, | ||
endIndex: index - 1 | ||
}); | ||
// console.log(imports[imports.length - 1]); | ||
resetImport(); | ||
} | ||
if (char === ';' || /[\n\r]/.test(char)) { | ||
var indexOffset = char === ';' ? 0 : -1; | ||
//we have reached the end of the import statement | ||
imports.push({ | ||
moduleIdentifier: moduleIdentifier, | ||
defaultImportName: defaultImportName, | ||
namedImports: namedImports || [], | ||
startIndex: startIndex, | ||
endIndex: index + indexOffset | ||
}); | ||
// console.log(imports[imports.length - 1]); | ||
resetImport(); | ||
} | ||
} | ||
} | ||
@@ -647,0 +683,0 @@ |
{ | ||
"name": "kremling", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/kremling.js", |
@@ -58,16 +58,18 @@ let bracesLevel, | ||
} | ||
} else if (/\s/.test(char) && lookingFor === 'DEFAULT_IMPORT_VAR_NAME') { | ||
// console.log('found default import name ' + currentWord); | ||
defaultImportName = currentWord.substring(0, currentWord.length - 1); | ||
resetWord(); | ||
if (namedImports === null) { | ||
// console.log('looking for named imports') | ||
lookingFor = `NAMED_IMPORTS`; | ||
} else { | ||
// console.log('looking for ') | ||
lookingFor = `FROM_KEYWORD`; | ||
} else if (lookingFor === 'DEFAULT_IMPORT_VAR_NAME') { | ||
if (/\s/.test(char) || char === ',') { | ||
// console.log(`found default import name '${currentWord}'`); | ||
defaultImportName = currentWord.substring(0, currentWord.length - 1); | ||
resetWord(); | ||
if (namedImports === null) { | ||
// console.log('looking for named imports') | ||
lookingFor = `NAMED_IMPORTS`; | ||
} else { | ||
// console.log('looking for FROM_KEYWORD') | ||
lookingFor = `FROM_KEYWORD`; | ||
} | ||
} | ||
} else if (lookingFor === 'NAMED_IMPORTS') { | ||
if (char === '{') { | ||
nameImports = []; | ||
namedImports = []; | ||
resetWord(); | ||
@@ -87,2 +89,3 @@ lookingFor = 'VARIABLE_LIST'; | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
lookingFor = 'NAMED_IMPORTS_COMMA'; | ||
@@ -97,5 +100,11 @@ } | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
} | ||
resetWord(); | ||
lookingFor = 'FROM_KEYWORD'; | ||
if (defaultImportName) { | ||
lookingFor = 'FROM_KEYWORD'; | ||
} else { | ||
// console.log('looking for imported vars') | ||
lookingFor = 'IMPORTED_VARS'; | ||
} | ||
} else if (char === ',') { | ||
@@ -107,2 +116,3 @@ // console.log('looking for named imports'); | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
} | ||
@@ -125,4 +135,10 @@ resetWord(); | ||
}); | ||
// console.dir(namedImports[namedImports.length - 1]); | ||
} | ||
lookingFor = 'FROM_KEYWORD'; | ||
if (defaultImportName) { | ||
lookingFor = 'FROM_KEYWORD'; | ||
} else { | ||
// console.log('looking for DEFAULT_IMPORT_COMMA ') | ||
lookingFor = 'DEFAULT_IMPORT_COMMA'; | ||
} | ||
resetWord(); | ||
@@ -132,2 +148,18 @@ } else { | ||
} | ||
} else if (lookingFor === 'DEFAULT_IMPORT_COMMA') { | ||
if (char === ',') { | ||
// console.log('looking for DEFAULT_IMPORT_VAR_NAME') | ||
lookingFor = 'DEFAULT_IMPORT_VAR_WHITESPACE'; | ||
resetWord(); | ||
} else if (/\s/.test(char)) { | ||
resetWord(); | ||
} else { | ||
lookingFor = 'FROM_KEYWORD'; | ||
} | ||
} else if (lookingFor === 'DEFAULT_IMPORT_VAR_WHITESPACE') { | ||
if (!(/\s/.test(char))) { | ||
lookingFor = 'DEFAULT_IMPORT_VAR_NAME'; | ||
} else { | ||
resetWord(); | ||
} | ||
} else if (lookingFor === 'FROM_KEYWORD') { | ||
@@ -155,8 +187,12 @@ if (currentWord === 'from') { | ||
} | ||
} else if (char === moduleIdentifierDelimiter) { | ||
lookingFor = 'END_OF_STATEMENT'; | ||
moduleIdentifier = currentWord.substring(0, currentWord.length - 1); | ||
// console.log('looking for end of statement') | ||
} else if (lookingFor === 'MODULE_IDENTIFIER'){ | ||
// console.log(`module identifier '${currentWord}'`) | ||
if (char === moduleIdentifierDelimiter) { | ||
// console.log('looking for end of statement') | ||
lookingFor = 'END_OF_STATEMENT'; | ||
moduleIdentifier = currentWord.substring(0, currentWord.length - 1); | ||
} | ||
} else if (lookingFor === 'END_OF_STATEMENT') { | ||
if (!(char === ';' || /\s/.test(char))) { | ||
if (char === ';' || /[\n\r]/.test(char)) { | ||
const indexOffset = char === ';' ? 0 : -1; | ||
//we have reached the end of the import statement | ||
@@ -168,3 +204,3 @@ imports.push({ | ||
startIndex, | ||
endIndex: index - 1, | ||
endIndex: index + indexOffset, | ||
}); | ||
@@ -171,0 +207,0 @@ // console.log(imports[imports.length - 1]); |
@@ -111,2 +111,3 @@ /* In terms of performance, I'm not as worried about excessive iteration here, but rather string | ||
return (importedThing.defaultImportName ? importedThing.defaultImportName : '') | ||
+ (importedThing.defaultImportName && importedThing.namedImports && importedThing.namedImports.length > 0 ? ', ' : '') | ||
+ importedThing.namedImports.map(namedImport => (namedImport.alias ? namedImport.alias : namedImport.name)) | ||
@@ -113,0 +114,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78368
39
1680
16