Skip to content

Commit

Permalink
adding tests and export check
Browse files Browse the repository at this point in the history
  • Loading branch information
navya9singh committed Jan 27, 2025
1 parent 7bbb51f commit 8aa6673
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/services/preparePasteEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import {
findAncestor,
forEachChild,
getTokenAtPosition,
isExportAssignment,
isExportDeclaration,
isExportSpecifier,
isIdentifier,
isImportClause,
isImportDeclaration,
isImportEqualsDeclaration,
isImportSpecifier,
isNamedExports,
isNamedImports,
isNamespaceImport,
rangeContainsPosition,
Expand All @@ -32,8 +36,9 @@ export function preparePasteEdits(
);
if (!enclosingNode) return;
if (
isImportSpecifier(enclosingNode) || isImportClause(enclosingNode) || isNamespaceImport(enclosingNode)
|| isImportEqualsDeclaration(enclosingNode) || isImportDeclaration(enclosingNode) || isNamedImports(enclosingNode)
isImportSpecifier(enclosingNode) || isImportClause(enclosingNode) || isNamespaceImport(enclosingNode) || isImportEqualsDeclaration(enclosingNode)
|| isImportDeclaration(enclosingNode) || isNamedImports(enclosingNode) || isExportSpecifier(enclosingNode) || isNamedExports(enclosingNode)
|| isExportAssignment(enclosingNode) || isExportDeclaration(enclosingNode)
) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion tests/cases/fourslash/preparePasteEdits_returnFalse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference path='./fourslash.ts' />

// @Filename: /file1.ts
//// [|import {abc} from "./file2";|]
//// [|const a = 1;|]
//// [|function foo() {
//// console.log("testing");}|]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference path='./fourslash.ts' />

// @Filename: /file1.ts
//// import {[|abc|]} from "[|./file2|]";
//// import [|{q}|] from [|"./file3"|];
//// [|import * as a from "./file2";|]
////
//// const b = 1;
//// const c = 2;
//// [|export {[|b|], c} from "./file1";|]

// @Filename: /file2.ts
//// export const abc = 1;

// @Filename: /file3.ts
//// export const q = 1;
verify.preparePasteEdits({
copiedFromFile: "/file1.ts",
copiedTextRange: test.ranges(),
providePasteEdits: false,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path='./fourslash.ts' />

// @allowJs: true
// @module: commonjs

// @Filename: /file1.ts
//// [|import [|t|] = require("./file2");|]
//// function add(a: number, b: number): number {
//// return a + b;
//// }
//// [|export = add;|]

// @Filename: /file2.ts
//// export const t = 1;

0 comments on commit 8aa6673

Please sign in to comment.