Skip to content

Commit

Permalink
Only use named exports internally
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Mar 21, 2020
1 parent 21d6a86 commit 036d204
Show file tree
Hide file tree
Showing 85 changed files with 285 additions and 277 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist').default
module.exports = require('./dist').YAML
2 changes: 1 addition & 1 deletion map.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = require('./dist/schema/Map').default
module.exports = require('./dist/schema/Map').YAMLMap
require('./dist/warnings').warnFileDeprecation(__filename)
2 changes: 1 addition & 1 deletion pair.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = require('./dist/schema/Pair').default
module.exports = require('./dist/schema/Pair').Pair
require('./dist/warnings').warnFileDeprecation(__filename)
2 changes: 1 addition & 1 deletion parse-cst.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/cst/parse').default
module.exports = require('./dist/cst/parse').parse
2 changes: 1 addition & 1 deletion scalar.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = require('./dist/schema/Scalar').default
module.exports = require('./dist/schema/Scalar').Scalar
require('./dist/warnings').warnFileDeprecation(__filename)
4 changes: 2 additions & 2 deletions schema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = require('./dist/schema').default
var opt = require('./dist/tags/options')
module.exports = require('./dist/schema').Schema
const opt = require('./dist/tags/options')
module.exports.nullOptions = opt.nullOptions
module.exports.strOptions = opt.strOptions
module.exports.stringify = require('./dist/stringify').stringifyString
Expand Down
2 changes: 1 addition & 1 deletion seq.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module.exports = require('./dist/schema/Seq').default
module.exports = require('./dist/schema/Seq').YAMLSeq
require('./dist/warnings').warnFileDeprecation(__filename)
22 changes: 13 additions & 9 deletions src/Anchors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import Alias from './schema/Alias'
import Map from './schema/Map'
import Merge from './schema/Merge'
import Scalar from './schema/Scalar'
import Seq from './schema/Seq'
import { Alias } from './schema/Alias'
import { YAMLMap } from './schema/Map'
import { Merge } from './schema/Merge'
import { Scalar } from './schema/Scalar'
import { YAMLSeq } from './schema/Seq'

export default class Anchors {
export class Anchors {
static validAnchorNode(node) {
return node instanceof Scalar || node instanceof Seq || node instanceof Map
return (
node instanceof Scalar ||
node instanceof YAMLSeq ||
node instanceof YAMLMap
)
}

map = {}
Expand All @@ -24,8 +28,8 @@ export default class Anchors {
const merge = new Merge()
merge.value.items = sources.map(s => {
if (s instanceof Alias) {
if (s.source instanceof Map) return s
} else if (s instanceof Map) {
if (s.source instanceof YAMLMap) return s
} else if (s instanceof YAMLMap) {
return this.createAlias(s)
}
throw new Error('Merge sources must be Map nodes or their Aliases')
Expand Down
20 changes: 10 additions & 10 deletions src/Document.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import addComment from './addComment'
import Anchors from './Anchors'
import { addComment } from './addComment'
import { Anchors } from './Anchors'
import { Char, Type } from './constants'
import {
YAMLError,
Expand All @@ -8,18 +8,18 @@ import {
YAMLSyntaxError,
YAMLWarning
} from './errors'
import listTagNames from './listTagNames'
import Schema from './schema'
import Alias from './schema/Alias'
import Collection, { isEmptyPath } from './schema/Collection'
import Node from './schema/Node'
import Scalar from './schema/Scalar'
import toJSON from './toJSON'
import { listTagNames } from './listTagNames'
import { Schema } from './schema'
import { Alias } from './schema/Alias'
import { Collection, isEmptyPath } from './schema/Collection'
import { Node } from './schema/Node'
import { Scalar } from './schema/Scalar'
import { toJSON } from './toJSON'

const isCollectionItem = node =>
node && [Type.MAP_KEY, Type.MAP_VALUE, Type.SEQ_ITEM].includes(node.type)

export default class Document {
export class Document {
static defaults = {
'1.0': {
schema: 'yaml-1.1',
Expand Down
2 changes: 1 addition & 1 deletion src/addComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function addCommentBefore(str, indent, comment) {
return `#${cc}\n${indent}${str}`
}

export default function addComment(str, indent, comment) {
export function addComment(str, indent, comment) {
return !comment
? str
: comment.indexOf('\n') === -1
Expand Down
6 changes: 3 additions & 3 deletions src/cst/Alias.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export default class Alias extends Node {
export class Alias extends Node {
/**
* Parses an *alias from the source
*
Expand Down
6 changes: 3 additions & 3 deletions src/cst/BlankLine.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Type } from '../constants'
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export default class BlankLine extends Node {
export class BlankLine extends Node {
constructor() {
super(Type.BLANK_LINE)
}
Expand Down
6 changes: 3 additions & 3 deletions src/cst/BlockValue.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Type } from '../constants'
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export const Chomp = {
CLIP: 'CLIP',
KEEP: 'KEEP',
STRIP: 'STRIP'
}

export default class BlockValue extends Node {
export class BlockValue extends Node {
constructor(type, props) {
super(type, props)
this.blockIndent = null
Expand Down
12 changes: 6 additions & 6 deletions src/cst/Collection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Type } from '../constants'
import BlankLine from './BlankLine'
import CollectionItem from './CollectionItem'
import Comment from './Comment'
import Node from './Node'
import Range from './Range'
import { BlankLine } from './BlankLine'
import { CollectionItem } from './CollectionItem'
import { Comment } from './Comment'
import { Node } from './Node'
import { Range } from './Range'

export function grabCollectionEndComments(node) {
let cnode = node
Expand Down Expand Up @@ -35,7 +35,7 @@ export function grabCollectionEndComments(node) {
return ca
}

export default class Collection extends Node {
export class Collection extends Node {
static nextContentHasIndent(src, offset, indent) {
const lineStart = Node.endOfLine(src, offset) + 1
offset = Node.endOfWhiteSpace(src, lineStart)
Expand Down
8 changes: 4 additions & 4 deletions src/cst/CollectionItem.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Type } from '../constants'
import { YAMLSemanticError } from '../errors'
import BlankLine from './BlankLine'
import Node from './Node'
import Range from './Range'
import { BlankLine } from './BlankLine'
import { Node } from './Node'
import { Range } from './Range'

export default class CollectionItem extends Node {
export class CollectionItem extends Node {
constructor(type, props) {
super(type, props)
this.node = null
Expand Down
6 changes: 3 additions & 3 deletions src/cst/Comment.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Type } from '../constants'
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export default class Comment extends Node {
export class Comment extends Node {
constructor() {
super(Type.COMMENT)
}
Expand Down
6 changes: 3 additions & 3 deletions src/cst/Directive.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Type } from '../constants'
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export default class Directive extends Node {
export class Directive extends Node {
constructor() {
super(Type.DIRECTIVE)
this.name = null
Expand Down
12 changes: 6 additions & 6 deletions src/cst/Document.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Char, Type } from '../constants'
import { YAMLSemanticError, YAMLSyntaxError } from '../errors'
import BlankLine from './BlankLine'
import { BlankLine } from './BlankLine'
import { grabCollectionEndComments } from './Collection'
import Comment from './Comment'
import Directive from './Directive'
import Node from './Node'
import Range from './Range'
import { Comment } from './Comment'
import { Directive } from './Directive'
import { Node } from './Node'
import { Range } from './Range'

export default class Document extends Node {
export class Document extends Node {
static startCommentOrEndBlankLine(src, start) {
const offset = Node.endOfWhiteSpace(src, start)
const ch = src[offset]
Expand Down
10 changes: 5 additions & 5 deletions src/cst/FlowCollection.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Type } from '../constants'
import { YAMLSemanticError } from '../errors'
import BlankLine from './BlankLine'
import Comment from './Comment'
import Node from './Node'
import Range from './Range'
import { BlankLine } from './BlankLine'
import { Comment } from './Comment'
import { Node } from './Node'
import { Range } from './Range'

export default class FlowCollection extends Node {
export class FlowCollection extends Node {
constructor(type, props) {
super(type, props)
this.items = null
Expand Down
4 changes: 2 additions & 2 deletions src/cst/Node.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Char, Type } from '../constants'
import { getLinePos } from './source-utils'
import Range from './Range'
import { Range } from './Range'

/** Root class of all nodes */
export default class Node {
export class Node {
static addStringTerminator(src, offset, str) {
if (str[str.length - 1] === '\n') return str
const next = Node.endOfWhiteSpace(src, offset)
Expand Down
22 changes: 11 additions & 11 deletions src/cst/ParseContext.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Char, Type } from '../constants'
import { YAMLSyntaxError } from '../errors'
import Alias from './Alias'
import BlockValue from './BlockValue'
import Collection from './Collection'
import CollectionItem from './CollectionItem'
import FlowCollection from './FlowCollection'
import Node from './Node'
import PlainValue from './PlainValue'
import QuoteDouble from './QuoteDouble'
import QuoteSingle from './QuoteSingle'
import Range from './Range'
import { Alias } from './Alias'
import { BlockValue } from './BlockValue'
import { Collection } from './Collection'
import { CollectionItem } from './CollectionItem'
import { FlowCollection } from './FlowCollection'
import { Node } from './Node'
import { PlainValue } from './PlainValue'
import { QuoteDouble } from './QuoteDouble'
import { QuoteSingle } from './QuoteSingle'
import { Range } from './Range'

function createNewNode(type, props) {
switch (type) {
Expand Down Expand Up @@ -47,7 +47,7 @@ function createNewNode(type, props) {
* @param {Node} parent - The parent of the node
* @param {string} src - Source of the YAML document
*/
export default class ParseContext {
export class ParseContext {
static parseType(src, offset, inFlow) {
switch (src[offset]) {
case '*':
Expand Down
6 changes: 3 additions & 3 deletions src/cst/PlainValue.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export default class PlainValue extends Node {
export class PlainValue extends Node {
static endOfLine(src, start, inFlow) {
let ch = src[start]
let offset = start
Expand Down
6 changes: 3 additions & 3 deletions src/cst/QuoteDouble.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { YAMLSemanticError, YAMLSyntaxError } from '../errors'
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export default class QuoteDouble extends Node {
export class QuoteDouble extends Node {
static endOfQuote(src, offset) {
let ch = src[offset]
while (ch && ch !== '"') {
Expand Down
6 changes: 3 additions & 3 deletions src/cst/QuoteSingle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { YAMLSemanticError, YAMLSyntaxError } from '../errors'
import Node from './Node'
import Range from './Range'
import { Node } from './Node'
import { Range } from './Range'

export default class QuoteSingle extends Node {
export class QuoteSingle extends Node {
static endOfQuote(src, offset) {
let ch = src[offset]
while (ch) {
Expand Down
2 changes: 1 addition & 1 deletion src/cst/Range.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default class Range {
export class Range {
static copy(orig) {
return new Range(orig.start, orig.end)
}
Expand Down
6 changes: 3 additions & 3 deletions src/cst/parse.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Published as 'yaml/parse-cst'

import Document from './Document'
import ParseContext from './ParseContext'
import { Document } from './Document'
import { ParseContext } from './ParseContext'

export default function parse(src) {
export function parse(src) {
const cr = []
if (src.indexOf('\r') !== -1) {
src = src.replace(/\r\n?/g, (match, offset) => {
Expand Down
4 changes: 2 additions & 2 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Node from './cst/Node'
import { Node } from './cst/Node'
import { getLinePos, getPrettyContext } from './cst/source-utils'
import Range from './cst/Range'
import { Range } from './cst/Range'

export class YAMLError extends Error {
constructor(name, source, message) {
Expand Down
2 changes: 1 addition & 1 deletion src/foldFlowLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const consumeMoreIndentedLines = (text, i) => {
* @param {function} options.onFold Called once if any line of text exceeds
* lineWidth characters
*/
export default function foldFlowLines(
export function foldFlowLines(
text,
indent,
mode,
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import parseCST from './cst/parse'
import YAMLDocument from './Document'
import { parse as parseCST } from './cst/parse'
import { Document as YAMLDocument } from './Document'
import { YAMLSemanticError } from './errors'
import Schema from './schema'
import { Schema } from './schema'
import { warn } from './warnings'

const defaultOptions = {
Expand Down Expand Up @@ -73,7 +73,7 @@ function stringify(value, options) {
return String(doc)
}

export default {
export const YAML = {
createNode,
defaultOptions,
Document,
Expand Down
Loading

1 comment on commit 036d204

@BurtHarris
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eemeli, I like this style, but could you explain what motivated the change?

Please sign in to comment.