Skip to content

Commit a010c15

Browse files
authored
(chore) add .js extension to import statements (#2601)
Adds file extensions to all import specifiers in ./src/ files. This is useful to run the files straight from source with a web browser , Node.js ESM or Deno. - Also add eslint rules regarding extensions for imports
1 parent 1936dbd commit a010c15

15 files changed

+33
-23
lines changed

.eslintrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ module.exports = {
3636
"indent": ["error", 2, {"VariableDeclarator":2}],
3737
// seems like a good idea not to use explicit undefined
3838
"no-undefined": "error",
39+
// ensure import specifier contains file extension
40+
"import/extensions": ["error", "always"],
3941

4042
// TODO maybe
4143
"camelcase": "off", // TODO: turn on later
4244
"init-declarations": ["error","always"]
4345
},
4446
"overrides": [
47+
{
48+
"files": ["src/**/*.js"],
49+
"rules": {
50+
// make sure there is no Node.js specific API slipping into the source files
51+
"import/no-nodejs-modules": "error",
52+
"import/no-commonjs": "error",
53+
}
54+
},
4555
{
4656
"files": ["src/languages/*.js"],
4757
"rules": {

src/highlight.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ Syntax highlighting with language autodetection.
33
https://highlightjs.org/
44
*/
55

6-
import deepFreeze from './vendor/deep_freeze';
7-
import Response from './lib/response';
8-
import TokenTreeEmitter from './lib/token_tree';
9-
import * as regex from './lib/regex';
10-
import * as utils from './lib/utils';
11-
import * as MODES from './lib/modes';
12-
import { compileLanguage } from './lib/mode_compiler';
6+
import deepFreeze from './vendor/deep_freeze.js';
7+
import Response from './lib/response.js';
8+
import TokenTreeEmitter from './lib/token_tree.js';
9+
import * as regex from './lib/regex.js';
10+
import * as utils from './lib/utils.js';
11+
import * as MODES from './lib/modes.js';
12+
import { compileLanguage } from './lib/mode_compiler.js';
1313
import * as packageJSON from '../package.json';
1414

1515
const escape = utils.escapeHTML;

src/languages/coffeescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Category: common, scripting
77
Website: https://coffeescript.org
88
*/
99

10-
import * as ECMAScript from "./lib/ecmascript";
10+
import * as ECMAScript from './lib/ecmascript.js';
1111

1212
/** @type LanguageFn */
1313
export default function(hljs) {

src/languages/groovy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Website: https://groovy-lang.org
66
*/
77

8-
import * as regex from "../lib/regex";
8+
import * as regex from '../lib/regex.js';
99

1010
function variants(variants, obj = {}) {
1111
obj.variants = variants;

src/languages/handlebars.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Website: https://handlebarsjs.com
77
Category: template
88
*/
99

10-
import * as regex from '../lib/regex'
10+
import * as regex from '../lib/regex.js'
1111

1212
export default function(hljs) {
1313
const BUILT_INS = {

src/languages/htmlbars.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ TODO: Remove in version 11.0.
1919
*/
2020

2121
// compile time dependency on handlebars
22-
import handlebars from "./handlebars"
22+
import handlebars from "./handlebars.js"
2323

2424
export default function(hljs) {
2525
const definition = handlebars(hljs)

src/languages/ini.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as regex from '../lib/regex';
1+
import * as regex from '../lib/regex.js';
22

33
/*
44
Language: TOML, also INI

src/languages/java.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Category: common, enterprise
55
Website: https://www.java.com/
66
*/
77

8-
import * as regex from "../lib/regex";
8+
import * as regex from '../lib/regex.js';
99

1010
export default function(hljs) {
1111
var JAVA_IDENT_RE = '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*';

src/languages/javascript.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Category: common, scripting
55
Website: https://developer.mozilla.org/en-US/docs/Web/JavaScript
66
*/
77

8-
import * as ECMAScript from "./lib/ecmascript";
9-
import * as regex from "../lib/regex";
8+
import * as ECMAScript from './lib/ecmascript.js';
9+
import * as regex from '../lib/regex.js';
1010

1111
export default function(hljs) {
1212
var IDENT_RE = ECMAScript.IDENT_RE;

src/languages/livescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Website: https://livescript.net
88
Category: scripting
99
*/
1010

11-
import * as ECMAScript from "./lib/ecmascript";
11+
import * as ECMAScript from './lib/ecmascript.js';
1212

1313
export default function(hljs) {
1414
var LIVESCRIPT_BUILT_INS = [

src/languages/typescript.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Website: https://www.typescriptlang.org
77
Category: common, scripting
88
*/
99

10-
import * as ECMAScript from "./lib/ecmascript";
10+
import * as ECMAScript from './lib/ecmascript.js';
1111

1212
export default function(hljs) {
1313
var IDENT_RE = ECMAScript.IDENT_RE;

src/lib/html_renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { escapeHTML } from './utils';
1+
import { escapeHTML } from './utils.js';
22

33
/**
44
* @typedef {object} Renderer

src/lib/mode_compiler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as regex from './regex';
2-
import { inherit } from './utils';
1+
import * as regex from './regex.js';
2+
import { inherit } from './utils.js';
33

44
// keywords that should have no default relevance value
55
var COMMON_KEYWORDS = 'of and for in not or if then'.split(' ');

src/lib/modes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { inherit } from './utils';
2-
import * as regex from './regex';
1+
import { inherit } from './utils.js';
2+
import * as regex from './regex.js';
33

44
// Common regexps
55
export const IDENT_RE = '[a-zA-Z]\\w*';

src/lib/token_tree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import HTMLRenderer from './html_renderer';
1+
import HTMLRenderer from './html_renderer.js';
22

33
/** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} | string} Node */
44
/** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} } DataNode */

0 commit comments

Comments
 (0)