Skip to content
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

Refactor rest of src/ as TypeScript #233

Merged
merged 24 commits into from Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1309fe7
Refactor more top-level files as TypeScript
eemeli Feb 21, 2021
4297c4e
Refactor stringify internals as TypeScript
eemeli Feb 21, 2021
1082a5f
Resolve inconsistency between Babel & tsc output for TS
eemeli Feb 21, 2021
bae8b4b
Drop babel-plugin-trace as unused
eemeli Feb 21, 2021
f4a74af
Refactor more internals as TS: Node, Scalar, Collection, createNode
eemeli Feb 21, 2021
0c2d254
Refactor collections as TS, adding generics
eemeli Feb 21, 2021
b89b20f
Refactor Alias as TS
eemeli Feb 21, 2021
d65a0e8
Drop AST namespace from typings
eemeli Feb 21, 2021
951e1f4
Add more generics; refactor last of src/ast/ as TS
eemeli Feb 21, 2021
904bbe7
Refactor stringify() as TypeScript
eemeli Feb 21, 2021
7fa4bb7
Refactor src/doc/ internals as TypeScript
eemeli Feb 21, 2021
1be58f8
Refactor Document as TypeScript, dropping wrapScalars option
eemeli Feb 21, 2021
1e8e448
Always set doc.schema in constructor, based on directives & version
eemeli Feb 22, 2021
7f491bf
Fix imports, adding .js extensions & resolving most circular dependen…
eemeli Feb 22, 2021
e42211b
Refactor failsafe & JSON tags as TypeScript, fixing tag object types
eemeli Feb 26, 2021
54a6f76
Refactor core & yaml-1.1 tags as TypeScript
eemeli Feb 26, 2021
b3c8986
Identify nodes by symbols rather than instanceof (no more dependency …
eemeli Feb 27, 2021
bf45235
Drop src/ast/index.ts re-exporter
eemeli Feb 27, 2021
7c4e0fe
Drop tests/typings.ts as obsolete
eemeli Feb 27, 2021
0a9f34f
Refactor test-events as TypeScript
eemeli Feb 27, 2021
ca909be
Rename src/ast/ -> src/nodes/
eemeli Feb 27, 2021
79e7da3
Enable ESLint for TypeScript files; fix issues
eemeli Feb 27, 2021
4ce72b3
Expose & test is* functions; add casting generic to documents
eemeli Feb 27, 2021
26f19b7
Fix test import paths
eemeli Feb 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions .eslintrc.yaml
@@ -1,34 +1,38 @@
root: true
parser: babel-eslint
parser: "@typescript-eslint/parser"
env:
node: true

plugins:
- "@typescript-eslint"

extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
- prettier

rules:
array-callback-return: error
camelcase: error
consistent-return: error
eqeqeq: [error, always, 'null': ignore]
consistent-return: 0
eqeqeq: [error, always, "null": ignore]
no-constant-condition: [error, checkLoops: false]
no-control-regex: 0
no-fallthrough: [error, commentPattern: fallthrough]
no-implicit-globals: error
no-template-curly-in-string: warn
no-unused-labels: 0
no-var: error
prefer-const: [warn, destructuring: all]
"@typescript-eslint/ban-ts-comment": off
"@typescript-eslint/explicit-module-boundary-types": off
"@typescript-eslint/no-explicit-any": off
"@typescript-eslint/no-namespace": off
"@typescript-eslint/no-unused-vars": off
"@typescript-eslint/no-unused-vars-experimental": warn

overrides:
- files: src/**/*.js
env:
es6: true
node: false
- files:
- tests/**/*.js
- files: [tests/**]
env:
es6: true
jest: true
rules:
camelcase: 0
25 changes: 17 additions & 8 deletions babel.config.js
@@ -1,13 +1,22 @@
module.exports = {
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-nullish-coalescing-operator',
['babel-plugin-trace', { strip: true }]
overrides: [
{
test: /\.js$/,
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-nullish-coalescing-operator'
]
},
{
test: /\.ts$/,
plugins: [
['@babel/plugin-transform-typescript', { allowDeclareFields: true }],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-nullish-coalescing-operator'
]
}
]
}

if (process.env.NODE_ENV === 'test')
module.exports.presets = [
['@babel/env', { targets: { node: 'current' } }],
'@babel/preset-typescript'
]
module.exports.presets = [['@babel/env', { targets: { node: 'current' } }]]
6 changes: 5 additions & 1 deletion docs/04_documents.md
Expand Up @@ -63,7 +63,11 @@ The `contents` of a parsed document will always consist of `Scalar`, `Map`, `Seq

#### `new YAML.Document(value, replacer?, options = {})`

Creates a new document. If `value` is defined, the document `contents` are initialised with that value, wrapped recursively in appropriate [content nodes](#content-nodes). If `value` is `undefined`, the document's `contents` and `schema` are initialised as `null`. If defined, a `replacer` may filter or modify the initial document contents, following the same algorithm as the [JSON implementation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter). See [Options](#options) for more information on the last argument.
Creates a new document.
If `value` is defined, the document `contents` are initialised with that value, wrapped recursively in appropriate [content nodes](#content-nodes).
If `value` is `undefined`, the document's `contents` is initialised as `null`.
If defined, a `replacer` may filter or modify the initial document contents, following the same algorithm as the [JSON implementation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter).
See [Options](#options) for more information on the last argument.

| Member | Type | Description |
| ------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
Expand Down
1 change: 0 additions & 1 deletion index.d.ts
@@ -1,2 +1 @@
export * from './dist/index'
export { AST } from './dist/ast/index'
8 changes: 4 additions & 4 deletions jest.config.js
Expand Up @@ -21,10 +21,10 @@ switch (process.env.npm_lifecycle_event) {
default:
process.env.TRACE_LEVEL = 'log'
moduleNameMapper = {
'^\\./dist$': '<rootDir>/src/index.js',
'^\\./dist/types(\\.js)?$': '<rootDir>/src/types.js',
'^\\./dist$': '<rootDir>/src/index.ts',
'^\\./dist/types(\\.js)?$': '<rootDir>/src/types.ts',
'^\\./dist/(.+)$': '<rootDir>/src/$1',
'^\\.\\./dist/test-events.js$': '<rootDir>/src/test-events.js'
'^\\.\\./dist/test-events.js$': '<rootDir>/src/test-events.ts'
}
}

Expand All @@ -33,7 +33,7 @@ module.exports = {
moduleNameMapper,
resolver: 'jest-ts-webcompat-resolver',
testEnvironment: 'node',
testMatch: ['**/tests/**/*.{js,ts}', '!**/tests/typings.ts'],
testMatch: ['**/tests/**/*.{js,ts}'],
testPathIgnorePatterns,
transform: { '/(src|tests)/.*\\.(js|ts)$': 'babel-jest' }
}