Skip to content

Ability to work with .vue files. #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ jspm_packages

# Optional npm cache directory
.npm
package-lock.json

# Optional REPL history
.node_repl_history

# IDEA directory
# Editor directories and files
.idea
.vscode
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"lodash.isfunction": "^3.0.8",
"lodash.isstring": "^4.0.1",
"lodash.startswith": "^4.2.1",
"minimatch": "^3.0.4"
"minimatch": "^3.0.4",
"vue-parser": "0.0.3"
}
}
42 changes: 41 additions & 1 deletion src/IncrementalChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import WorkSet = require('./WorkSet');
import NormalizedMessage = require('./NormalizedMessage');
import CancellationToken = require('./CancellationToken');
import minimatch = require('minimatch');
import vueParser = require('vue-parser');

// Need some augmentation here - linterOptions.exclude is not (yet) part of the official
// types for tslint.
Expand Down Expand Up @@ -107,7 +108,46 @@ class IncrementalChecker {
});
}

return files.getData(filePath).source;
let source = files.getData(filePath).source;

// get typescript contents from Vue file
if (path.extname(filePath) === '.vue') {
const parsed = vueParser.parse(source.text, 'script', { lang: 'ts' });
source = ts.createSourceFile(filePath, parsed, languageVersion);
}

return source;
};

host.fileExists = function fileExists(fileName) {
return ts.sys.fileExists(fileName);
};

host.readFile = function readFile(fileName) {
return ts.sys.readFile(fileName);
};

host.resolveModuleNames = (moduleNames, containingFile) => {
const resolvedModules: ts.ResolvedModule[] = [];

for (const moduleName of moduleNames) {
// Try to use standard resolution.
const result = ts.resolveModuleName(moduleName, containingFile, programConfig.options, {
fileExists: host.fileExists,
readFile: host.readFile
});

if (result.resolvedModule) {
resolvedModules.push(result.resolvedModule);
} else {
// For non-ts extensions.
resolvedModules.push({
resolvedFileName: moduleName,
extension: '.ts'
} as ts.ResolvedModuleFull);
}
}
return resolvedModules;
};

return ts.createProgram(
Expand Down