Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new change_1.NoopChange();
}
// no such import declaration exists
var useStrict = ast_utils_1.findNodes(rootNode, ts.SyntaxKind.StringLiteral).filter(function (n) { return n.getText() === 'use strict'; });
var fallbackPos = 0;
if (useStrict.length > 0) {
fallbackPos = useStrict[0].end;
}
var open = isDefault ? '' : '{ ';
var close = isDefault ? '' : ' }';
// if there are no imports or 'use strict' statement, insert import at beginning of file
var insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
var separator = insertAtBeginning ? '' : ';\n';
var toInsert = separator + "import " + open + symbolName + close +
(" from '" + fileName + "'" + (insertAtBeginning ? ';\n' : ''));
return ast_utils_1.insertAfterLastOccurrence(allImports, toInsert, fileToEdit, fallbackPos, ts.SyntaxKind.StringLiteral);
}
exports.insertImport = insertImport;
relevantImports.forEach(function (n) {
Array.prototype.push.apply(imports_1, ast_utils_1.findNodes(n, ts.SyntaxKind.Identifier));
if (ast_utils_1.findNodes(n, ts.SyntaxKind.AsteriskToken).length > 0) {
importsAsterisk_1 = true;
}
});
// if imports * from fileName, don't add symbolName
if (importsAsterisk_1) {
return new change_1.NoopChange();
}
var importTextNodes = imports_1.filter(function (n) { return n.text === symbolName; });
// insert import if it's not there
if (importTextNodes.length === 0) {
var fallbackPos_1 = ast_utils_1.findNodes(relevantImports[0], ts.SyntaxKind.CloseBraceToken)[0].getStart() ||
ast_utils_1.findNodes(relevantImports[0], ts.SyntaxKind.FromKeyword)[0].getStart();
return ast_utils_1.insertAfterLastOccurrence(imports_1, ", " + symbolName, fileToEdit, fallbackPos_1);
}
return new change_1.NoopChange();
}
// no such import declaration exists
var useStrict = ast_utils_1.findNodes(rootNode, ts.SyntaxKind.StringLiteral).filter(function (n) { return n.getText() === 'use strict'; });
var fallbackPos = 0;
if (useStrict.length > 0) {
fallbackPos = useStrict[0].end;
}
var open = isDefault ? '' : '{ ';
var close = isDefault ? '' : ' }';
// if there are no imports or 'use strict' statement, insert import at beginning of file
var insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
var separator = insertAtBeginning ? '' : ';\n';
var toInsert = separator + "import " + open + symbolName + close +
(" from '" + fileName + "'" + (insertAtBeginning ? ';\n' : ''));